/* A test program for the functions provided by strLists.c. * Allows the client to test repeatedly. * @Author Wanlin Liu * Created February 11, 2000 * Version 1.2 of February 15, 2000 */ #include "list.h" main() { int i,j; char str[100]; list head = null; while(1) { printf("Enter your choice: \n"); printf("1: read from a file. \n"); printf("2: write to a file. \n"); printf("3: delete a node.\n"); printf("4: sort the list.\n"); printf("5: print out the list.\n"); printf("6: print out a file. \n"); printf("7: insert a new node after the current node.\n"); printf("8: print out the current string.\n"); printf("9: quit. \n"); scanf("%d", &i); switch(i) { case 1 : printf("Please enter file name.\n"); scanf("%s", str); printf("The name of the file is %s.\n", str); head = listread(str); listprint(head); break; case 2 : printf("Please enter file name. \n"); scanf("%s", str); if(!head) printf("There is nothing in the list to write to the file.\n"); else listwrite(head, str); break; case 3 : if(head==null) printf("List not existent.\n"); else { printf("Enter your choice for deletion:\n1: Delete all occurences\n2: delete first occurence.\n3: delete nth element.\n"); scanf("%d", &i); if(i==3) { printf("Enter the position.\n"); scanf("%d",&j); delete_nth_node(head, j); } else if((i==1) || (i==2)) { printf("Enter the string you want to delete.\n"); scanf("%s", str); if(i==1) delete_elements(head, str); else if(i==2) delete_element(head, str); } else printf("Invalid entry. Mission aborted.\n"); } break; case 4 : if(head==null) { printf("List not existent.\n"); break; } else { head = (list)quicksort(head); break; } case 5 : if(head == null) printf("The list is empty.\n"); else listprint(head); break; case 6 : printf("Please enter file name. \n"); scanf("%s", str); printfile(str); break; case 7 : printf("Please enter the string you want to insert. \n"); scanf("%s", str); if(head == null) { head = initialize(); insert(head, str); printf("Strng %s inserted successfully.\n", str); } else { insert(head, str); printf("Strng %s inserted successfully.\n", str); } break; case 8 : if (head == null) printf("The the list is empty.\n"); else printcurrent(head); break; case 9 : free(head); exit(0); default : printf("Invalid entry, please try again.\n"); break; } } }