/* listtest.c - Interactive tester for manipulating doubly linked lists. * Authors: Amit Nangalia * Last modified: 17th February, 2000 */ #include #include "openfile.h" #include "listfunc.h" /* Presents an interactive menu to the user to manipulate lists */ int menu(); /* Executes the choices chosen by the user from the menu */ void selection(int choice); NODE *mylist; main() { int choice; while (choice != 6) { choice = menu(); selection(choice); } }/* main */ int menu() { int input; printf("\n\n"); printf("Please make a choice:\n"); printf("**********************\n\n"); printf("1 - Enter strings from a text file into list\n"); printf("2 - Insert a single string into the list\n"); printf("3 - Output list to screen\n"); printf("4 - Output list to a text file\n"); printf("5 - Delete element from list\n"); printf("6 - QuickSort the list\n"); printf("7 - Exit\n"); printf("Enter your selection: \n"); scanf("%d", &input); return (input); } void selection(int choice) { FILE *fp = NULL; char str[BUFSIZE]; int flag; /* To prevent other functions from attempting to work on a list that hasn't even been created */ switch(choice) { case 1: mylist = create(); fp = filereader("r"); /* Set flag to 1.*/ flag = 1; while (fgets(str, BUFSIZE, fp)) { insert(mylist, str); } printf("Inserted elements into the list\n"); fclose(fp); break; case 2: if (flag != 1) printf("No linked list created to insert into\n"); else { printf("what string do you want to insert: \n"); scanf("%s", str); insert(mylist, str); } break; case 3: if (flag != 1) printf("No linked list created to read from\n"); else { traverse(mylist); printf("done printing out the list\n"); } break; case 4: if (flag != 1) printf("No linked list created to output from\n"); else { fp = filereader("w+"); toFile(mylist, fp); printf("done outputting\n"); } break; case 5: if (flag != 1) printf("No linked list created to delete from\n"); else { printf("what string do you want to delete: \n"); scanf("%s", str); delete(mylist, str); } break; case 6: if (flag != 1) printf("no linked list created to sort\n"); else /* Sort the list. All functions after having performed the sort, will be on the sorted list. */ mylist = sort(mylist); break; case 7: printf("Hope you liked working with LISTS. BYE BYE!\n"); exit(0); default: puts("Invalid entry, try again!\n"); } }