Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include "lab07.h"
  2.  
  3.  
  4. int main()
  5. {
  6. cout << "Paul Madsen" << endl;
  7.     cout << "CS 1410 002" << endl;
  8.     cout << "lab 7" << endl;
  9.     const int AMOUNT_MAX = 10;
  10.     srand(time(0));
  11.     //create list
  12.     List* myList = new List();
  13.  
  14.     //create nodes and fill list
  15.     string item = "eggs";
  16.     int amount = rand() % AMOUNT_MAX + 1;
  17.     string ui = "dozen";
  18.     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
  19.     myList->push_back(aNode);
  20.  
  21.     item = "bacon";
  22.     amount = rand() % AMOUNT_MAX + 1;
  23.     ui = "package";
  24.     Node* aNode2 = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL);
  25.     myList->push_back(aNode2);
  26.  
  27.     item = "pancake mix";
  28.     amount = rand() % AMOUNT_MAX + 1;
  29.     ui = "package";
  30.     aNode = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL);
  31.     myList->push_back(aNode);
  32.  
  33.     item = "milk";
  34.     amount = rand() % AMOUNT_MAX + 1;
  35.     ui = "gallon";
  36.     aNode = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL);
  37.     myList->push_back(aNode);
  38.  
  39.     myList->DisplayList(); //display list thus far
  40.  
  41.     //add item to front of list and display
  42.     item = "pork & beans";
  43.     amount = rand() % AMOUNT_MAX + 1;
  44.     ui = "can";
  45.     aNode = new Node((char*)item.c_str(), (unsigned int)amount, (char*)ui.c_str(),NULL, NULL, NULL);
  46.     myList->push_front(aNode);
  47.     myList->DisplayList();
  48.  
  49.     //remove item from front and display
  50.     Node* removedNode = myList->pop_front();
  51.     myList->DisplayList();
  52.     cout << "Item removed from list: " << removedNode->GetItem();
  53.     delete removedNode;
  54.  
  55.     //remove item from end and display
  56.     removedNode = myList->pop_back();
  57.     myList->DisplayList();
  58.     cout << "Item removed from list: " << removedNode->GetItem();
  59.     delete removedNode;
  60.  
  61.     //demonstrate functionality of GetData() function
  62.     stringstream ss = myList->GetData(rand() % myList->GetNumberOfNodes() + 1);
  63.     cout << "GetData returned: " << ss << endl;
  64.  
  65.  
  66.     system("PAUSE");
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement