Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "lab07.h"
- int main()
- {
- cout << "Paul Madsen" << endl;
- cout << "CS 1410 002" << endl;
- cout << "lab 7" << endl;
- const int AMOUNT_MAX = 10;
- srand(time(0));
- //create list
- List* myList = new List();
- //create nodes and fill list
- string item = "eggs";
- int amount = rand() % AMOUNT_MAX + 1;
- string ui = "dozen";
- Node* aNode = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL); //last three values are assigned by list class
- myList->push_back(aNode);
- item = "bacon";
- amount = rand() % AMOUNT_MAX + 1;
- ui = "package";
- Node* aNode2 = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL);
- myList->push_back(aNode2);
- item = "pancake mix";
- amount = rand() % AMOUNT_MAX + 1;
- ui = "package";
- aNode = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL);
- myList->push_back(aNode);
- item = "milk";
- amount = rand() % AMOUNT_MAX + 1;
- ui = "gallon";
- aNode = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL);
- myList->push_back(aNode);
- myList->DisplayList(); //display list thus far
- //add item to front of list and display
- item = "pork & beans";
- amount = rand() % AMOUNT_MAX + 1;
- ui = "can";
- aNode = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL);
- myList->push_front(aNode);
- myList->DisplayList();
- //remove item from front and display
- Node* removedNode = myList->pop_front();
- myList->DisplayList();
- cout << "Item removed from list: " << removedNode->GetItem();
- delete removedNode;
- //remove item from end and display
- removedNode = myList->pop_back();
- myList->DisplayList();
- cout << "Item removed from list: " << removedNode->GetItem();
- delete removedNode;
- //demonstrate functionality of GetData() function
- stringstream ss = myList->GetData(rand() % myList->GetNumberOfNodes() + 1);
- cout << "GetData returned: " << ss << endl;
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement