#include "linkedlist.h" #include "QuickSort.h" #include "ReadFile.h" #include /* This is a tester. */ void printMenu(); int main() { node *alist; int option; /* the menu choice */ char str[64]; /* a string for adding items to the list */ char filename[64]; /* a string used for the name of the file to read or write to */ printf("This is an interface to test the linked-list functions that Jon and Sarah wrote.\n\n"); printMenu(); scanf ("%d", &option); /* loop until they want to quit */ while (option != 1) { /* depending on the option they typed, do the proper command */ switch(option) { case 2: if (alist == NULL) { printf("\nWhat string would you like to put in this new list? "); scanf("%s", &str); alist = newList(str); } else { printf("\nThe list has already been created.\n"); } break; case 3: if (alist != NULL) { printf("\nWhat string would you like to add? "); scanf("%s", &str); alist = addAfterCurrent(alist, str); } else { printf("\nThe list has not been created. Enter a string to create a new list: "); scanf("%s", &str); alist = newList(str); } break; case 4: if (alist != NULL) { printf("\nWhat string would you like to add? "); scanf("%s", &str); alist = addToEnd(alist, str); } else { printf("\nThe list has not been created. Enter a string to create a new list: "); scanf("%s", &str); alist = newList(str); } break; case 5: if (alist != NULL) { printf("\nThe current element is: %s\n", getCurrent(alist)); } else { printf("\nError, the list has not been created.\n"); } break; case 6: if (alist != NULL) { /* call a function to print the entire list */ listPrint(alist); } else { printf("\nError, the list has not been created.\n"); } break; case 7: if (alist != NULL) { /* Get the next element in the list */ alist = getNext(alist); } else { printf("\nError, the list has not been created.\n"); } break; case 8: if (alist != NULL) { /* Get the previous element in the list */ alist = getPrev(alist); } else { printf("\nError, the list has not been created.\n"); } break; case 9: if (alist != NULL) { /* Get the first element in the list */ alist = getFirst(alist); } else { printf("\nError, the list has not been created.\n"); } break; case 10: if (alist != NULL) { /* Get the last element in the list */ alist = getLast(alist); } else { printf("\nError, the list has not been created.\n"); } break; case 11: if (alist != NULL) { /* Ask for a string */ printf("\nWhat string would you like to look for? "); scanf("%s", &str); /* call findElt to search for that string */ alist = findElt(alist, str); } else { printf("\nError, the list has not been created.\n"); } break; case 12: if (alist != NULL) { /* Ask for a string */ printf("\nWhat string would you like to look for? "); scanf("%s", &str); /* call deleteElt */ alist = deleteElt(alist, str); } else { printf("\nError, the list has not been created.\n"); } break; case 13: if (alist != NULL) { /* call quicksort with the list */ alist = quickSort(alist); } else { /* the list is null */ printf("\nError, the list has not been created.\n"); } break; case 14: if (alist != NULL) { /* Ask for a filename */ printf("\nEnter a filename: "); scanf("%s", &filename); alist = readFile(filename); } else { /* the list is null */ printf("\nError, the list has not been created.\n"); } break; case 15: if (alist != NULL) { /* Ask for a filename */ printf("\nEnter a filename: "); scanf("%s", &filename); alist = writeFile(filename, alist); } else { /* the list is null */ printf("\nError, the list has not been created.\n"); } break; default: printf("\nYou didn't enter a valid menu option. Please try again. \n"); } /* switch */ /* Read input again */ printf("\nEnter another option, or type '0' to print the menu again: "); scanf ("%d", &option); if(option == 0) { printMenu(); scanf ("%d", &option); } } /* while */ return 1; } void printMenu() { /* print beginning messages to the user */ printf(" ***** MENU *****\n\n"); printf(" 1. Quit\n"); printf(" 2. Create a new list\n"); printf(" 3. Add an element after the current one\n"); printf(" 4. Add an element to the end of the list\n"); printf(" 5. Print the current element\n"); printf(" 6. Print the entire list\n"); printf(" 7. Move to the next element\n"); printf(" 8. Move to the previous element\n"); printf(" 9. Move to the beginning of the list\n"); printf(" 10. Move to the end of the list\n"); printf(" 11. Find a string in the list and get that element\n"); printf(" 12. Delete a string from the list\n"); printf(" 13. Sort the list\n"); printf(" 14. Read the list from a textfile\n"); printf(" 15. Write the list to a textfile\n"); printf("\nEnter the number of the option you'd like to do: "); }