Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include "unsorted_list.h"
  3.  
  4. using namespace std;
  5.  
  6. void print (UnsortedList<int>* list) {
  7.     int i = list->getLength(), item;
  8.     list->reset();
  9.  
  10.     while (i--) {
  11.         list->getNext(item);
  12.         cout << item << " ";
  13.     }
  14.  
  15.     cout << endl;
  16. }
  17.  
  18. int main () {
  19.     // Create a list
  20.     UnsortedList<int> list;
  21.  
  22.     // Insert 4 items and print all items
  23.     int i = 4, input;
  24.     while (i--) {
  25.         cin >> input;
  26.         list.insert(input);
  27.     }
  28.     print(&list);
  29.  
  30.     // Print length of the list
  31.     cout << list.getLength() << endl;
  32.  
  33.     // Add another item
  34.     cin >> input;
  35.     list.insert(input);
  36.     print(&list);
  37.  
  38.     // Retrieve 4 and print whether found or not
  39.     int number = 4;
  40.     bool found;
  41.     list.retrieve(number, found);
  42.     if (!found)
  43.         cout << "Item is not found" << endl;
  44.  
  45.     // Retrieve 5 and print whether found or not
  46.     number = 5;
  47.     list.retrieve(number, found);
  48.     if (found)
  49.         cout << "Item is found" << endl;
  50.  
  51.     // Retrieve 9 and print whether found or not
  52.     number = 9;
  53.     list.retrieve(number, found);
  54.     if (found)
  55.         cout << "Item is found" << endl;
  56.  
  57.     // Retrieve 10 and print whether found or not
  58.     number = 10;
  59.     list.retrieve(number, found);
  60.     if (!found)
  61.         cout << "Item is not found" << endl;
  62.  
  63.     // Print if the list is full or not
  64.     if (!list.isFull())
  65.         cout << "List is not full" << endl;
  66.  
  67.     // Delete 5 and see if the list is full or not
  68.     list.remove(5);
  69.     if (!list.isFull())
  70.         cout << "List is not full" << endl;
  71.  
  72.     // Delete 1 and print the list
  73.     list.remove(1);
  74.     print(&list);
  75.  
  76.     // Delete 6 and print the list
  77.     list.remove(6);
  78.     print(&list);
  79.  
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement