int main (void) { /* program to coordinate the menu options and calls the requested function */ struct node * first = NULL; /* pointer to the first list item */ char option[strMax]; /* user response to menu selection */ printf ("Program to Maintain a List of Names\n"); while (1) { /* print menu options */ printf ("Options available\n"); printf ("I - Insert a name into the list\n"); printf ("D - Delete a name from the list\n"); printf ("C - Count the number of items on the list\n"); printf ("F - Move an item to the front of the list\n"); printf ("L - Print the last item on the list (iteratively)\n"); printf ("M - Print the last item on the list (recursively)\n"); printf ("P - Print the names on the list (iteratively)\n"); printf ("S - Print the names on the list (recursively)\n"); printf ("R - Print the names in reverse order\n"); printf ("Q - Quit\n"); /* determine user selection */ printf ("Enter desired option: "); scanf ("%s", option); switch (option[0]) { case 'I': case 'i': addName(&first); break; case 'D': case 'd': deleteName(&first); break; case 'C': case 'c': countList(first); break; case 'F': case 'f': putFirst(&first); break; case 'L': case 'l': printLast(first); break; case 'M': case 'm': printLastRec(first); break; case 'P': case 'p': print(first); break; case 'S': case 's': printRec(first); break; case 'R': case 'r': printReverse(first); break; case 'Q': case 'q': printf ("Program terminated\n"); return 0; break; default: printf ("Invalid Option - Try Again!\n"); continue; } } }
/**** * * Test driver for exercising the functions of GeneralList. * */ int main() { char* intArray[] = {"1","2","3"}; // Intializing array GeneralList* listOfStrings; // Test list holding strings GeneralList* listOfIntegers; // Test list holding Integers /* * Allocate. */ listOfStrings = newGeneralList(); listOfIntegers = newGeneralListArray((char**) intArray, sizeof(intArray) / sizeof(char*)); /* * Call the constructive methods. */ putLast(putLast(putLast(listOfStrings, "x"), "y"), "z"); putFirst(putFirst(putFirst(listOfStrings, "c"), "b"), "a"); put(put(listOfStrings, "m", 3), "n", 4); set(listOfStrings, "N", 4); put(listOfIntegers, "4", 3); /* * Print out the results of the constructive methods. */ printf("\nConstruction results:\n"); printf("%s\n", toString(listOfStrings)); printf("%s\n", toString(listOfIntegers)); /* * Call the non-destructive access methods, printing out results * incrementally. */ printf( "\nFirst, last, and middle elements of string list are: %s, %s, %s\n", getFirst(listOfStrings), getLast(listOfStrings), get(listOfStrings, 3) ); /* * Call the destructive access methods, printing out results incrementally. */ printf( "\nRemoved first, last, and middle elements of string list are: %s, %s, %s\n", removeFirst(listOfStrings), removeLast(listOfStrings), removeIth(listOfStrings, 2) ); printf("String list after removals is: %s\n", toString(listOfStrings)); printf( "\nMore removed -- first, last, and middle elements of string list are: %s, %s, %s\n", removeIth(listOfStrings, 0), removeIth(listOfStrings, 3), removeIth(listOfStrings, 1) ); printf("String list after more removals is: %s\n", toString(listOfStrings)); /* * Put back some elements for utility method testing. */ put(put(put(listOfStrings, "b", 0), "N", 2), "y", 4); printf("String list after put backs: %s\n", toString(listOfStrings)); /* * Call the utility methods. */ printf( "\nResults of elementOf(\"b\"), elementOf(\"X\"), findIndex(\"N\"), findIndex(\"X\"):\n" ); printf("%s, %s, %d, %d\n", elementOf(listOfStrings, "b") ? "true" : "false", elementOf(listOfStrings, "X") ? "true" : "false", findIndex(listOfStrings, "N"), findIndex(listOfStrings, "X") ); printf("\nResults of sorting: %s\n", toString(sort(listOfStrings))); /* * Call the utility methods. */ printf( "\nResults of subList(2,3), length, isEmpty, equals, and toString:\n" ); printf("%s, %d, %s, %s, %s\n", toString(subList(listOfStrings, 2, 3)), length(listOfStrings), isEmpty(listOfStrings) ? "true" : "false", equals(listOfStrings, listOfIntegers) ? "true" : "false", toString(listOfStrings) ); /* * Do another sort. */ putLast(putLast(putLast(putLast(listOfStrings, "4"), "3"), "2"), "1"); printf("\nBefore 2nd sort: %s\n", toString(listOfStrings)); printf("Results of 2nd sort: %s\n", toString(sort(listOfStrings))); printf("\n"); return 0; }
int main (void) { /* program to coordinate the menu options and calls the requested function */ struct node * first = NULL; /* pointer to the first list item */ char option[strMax]; /* user response to menu selection */ printf ("Program to Maintain a List of Robot Actions\n"); while (1) { /* print menu options */ printf ("Options available\n"); printf ("I - Insert an action into the list\n"); printf ("D - Delete an action from the list\n"); printf ("C - Count the number of items in the list\n"); printf ("F - Move an item to the front of the list\n"); printf ("L - Print the last item in the list\n"); printf ("P - Print the actions in the list and the UIDs of the nodes\n"); printf ("R - Print the actions and UIDs in reverse order\n"); printf ("E - Execute all the action commands contained in the list\n"); printf ("Q - Quit\n"); /* determine user selection */ printf ("Enter desired option: "); scanf ("%s", option); switch (option[0]) { case 'I': case 'i': addAction(&first); break; case 'D': case 'd': deleteAction(&first); break; case 'C': case 'c': countList(first); break; case 'F': case 'f': putFirst(&first); break; case 'L': case 'l': printLast(first); break; case 'P': case 'p': print(first); break; case 'R': case 'r': printReverse(first); break; case 'E': case 'e': executeActions(first); break; case 'Q': case 'q': printf ("Program terminated\n"); return 0; break; default: printf ("Invalid Option - Try Again!\n"); continue; } } }