Email your source code to dannellys2@winthrop.edu by the beginning of class on Thursday Feb 3. Submit your file using Pine. I will use the g++ compiler to test your code.
#include < iostream.h> #include < stdlib.h> // your name here // data structures lab two // january 27, 2005 // program that manipulates a linked list struct node { int value; node *next; }; /********************************************************/ // Function to print a linked list. void print_list (node *head) { node *temp; for (temp=head; temp!=NULL; temp=temp->next) cout << temp->value << " "; cout << endl; } /********************************************************/ int main() { char choice; int data_val; node *head; // issue instructions cout << "Possible Commands:\n\t"; cout << "add --> \ta value\n\tdelete -->\td value"; cout << "\n\tprint -->\tp\n\tquit -->\tq\n"; // process commands for(;;) { cin >> choice; switch (choice) { case 'a': case 'A': cin >> data_val; add_node (&head, data_val); break; case 'd': case 'D': cin >> data_val; delete_node (&head, data_val); break; case 'p': case 'P': print_list(head); break; case 'q': case 'Q': exit(1); break; default : cout << "Unknown command! Choose a, d, p or q\n"; } } }
Possible Commands: add --> a value delete --> d value print --> p quit --> q a 88 a 44 T Unknown command! Choose a, d, p or q P 44 88 d 99 No such value in list - 99! d 44 p 88 Q