int main(int argc, const char * argv[]) { // insert code here... LNode *head = initStuTable(); srand((unsigned)time(NULL)); /*随机种子*/ for (int i = 0; i < 2; ++i) { Student stu; sprintf(stu.stuID, "%s%d","no",i); stu.mathScore = rand()%99; stu.englishScore= rand()%99; addStu(stu); } Student stu; sprintf(stu.stuID, "%s%d","no",111); stu.mathScore = 111; stu.englishScore= 111; addStu(stu); printf("after add :\n"); displayStuTable(); // // displayStuTable(); LNode *result = searchStu("no111"); reverseList(head); displayStuTable(); // // // // // printf("after add :\n"); // // displayStuTable(); // deleteStu(stu); // // printf("after delete :\n"); // // // displayStuTable(); return 0; }
int main(){ FILE *fp; fp = fopen("phones.txt", "r+"); char name[30]; char phone[20]; BST_TREE* list; list = BST_Create (compareStu); // while(!feof(fp)){...} while(fscanf(fp, "%s %s", name, phone) == 2){ // printf("%s, %s\n", name, phone); addStu(list, name, phone); }; fclose(fp); char option = ' '; while ( (option = getOption ()) != 'Q'){ switch (option){ case 'A': printf("Input name: "); scanf("%s", name); printf("Input phone: "); scanf("%s", phone); addStu (list, name, phone); break; case 'D': deleteStu (list); break; case 'F': findStu (list); break; case 'P': printList (list); break; } // switch } // while fp = fopen("phones.txt", "w"); BST_Traverse (list, saveStu); fclose(fp); list = BST_Destroy (list); printf("\nEnd Student List\n"); return 0; }