/********************************************************************* C201 Computer Programming II Fall 2006 Dana Vrajitoru & A test for the linked lists. **********************************************************************/ #include "list.h" #include using namespace std; // Prototypes for functions defined here. void Print_menu(); void Execute_menu(char option, Node_ptr &front); int main() { char option = '\0'; Node_ptr front = NULL; while (option != 'q' && option != 'Q') { Print_menu(); cin >> option; Execute_menu(option, front); } return 0; } void Print_menu() { cout << endl << "Choose an action from the following:" << endl << "[A] Add a new node to the front of the list" << endl << "[B] Add a new node to the back of the list" << endl << "[C] Concatenate the words in the list" << endl << "[D] Delete the front node from the list" << endl << "[F] Find a word in the list" << endl << "[I] Print the element number i in the list" << endl << "[K] Capitalize all the words in the list" << endl << "[L] Convert all the words in the list to lowercase" << endl << "[R] Reverse the list" << endl << "[P] Print the entire list" << endl << "[Q] quit" << endl; } void Execute_menu(char option, Node_ptr &front) { string s; switch (option) { case 'q': case 'Q': Delete_list(front); Output_list(front); cout << "Goodbye." << endl; break; case 'a': case 'A': cout << "Enter a word to add to the front of the list" << endl; cin >> s; Insert_front(front, s); break; case 'b': case 'B': cout << "Enter a word to add to the back of list" << endl; cin >> s; Insert_back(front, s); break; case 'c': case 'C': s = Concatenate(front); cout << "The concatenated list is: " << endl << s << endl; break; case 'd': case 'D': Remove_front(front); break; case 'f': case 'F': cout << "Enter a word to find in the list." << endl; cin >> s; if (Search(front, s) != NULL) cout << "The word is in the list" << endl; else cout << "The word is not in the list" << endl; break; case 'i': case 'I': int i; cout << "Enter the position of the word in the list" << endl; cin >> i; cout << "The word at position i is " << Access_index(front, i)->word << endl; break; case 'k': case 'K': Toupper_all(front); break; case 'l': case 'L': Tolower_all(front); break; case 'r': case 'R': Reverse_list(front); break; case 'p': case 'P': cout << "The list has " << Count_nodes(front) << " nodes:" << endl; Output_list(front); break; default: cout << "Wrong option, try again" << endl; } }