Phr0zen_Penguin

SList.cpp - VTC C++ Data Structures Sorted List Example

Apr 6th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. /**
  2.  * [SList.cpp]
  3.  * Sorted list example.
  4.  *
  5.  * compiler:
  6.  * TDM-GCC 4.9.2 64-bit
  7.  *
  8.  * compile with:
  9.  * g++ -m32 -static-libgcc -o slist SList.cpp SortedList.cpp
  10.  */
  11.  
  12. #include "SortedList.h"
  13.  
  14. int main(void)
  15. {
  16.     /**
  17.      * Sorted List OBJECT CREATION:
  18.      *
  19.      * A pointer is used for pointers are very effective in reducing pushing and popping on the stack,
  20.      * among other things.
  21.      */
  22.     SortedList  *SList = new SortedList();
  23.  
  24.  
  25.     /**
  26.      * Sorted List ITEM INSERTION (In Random Order):
  27.      */
  28.     SList->InsertItem(2.5);
  29.     SList->InsertItem(1.5);
  30.     SList->InsertItem(1);
  31.     SList->InsertItem(1.4);
  32.     SList->InsertItem(1.5);
  33.  
  34.  
  35.     /**
  36.      * Sorted List ITEM OUTPUT:
  37.      */
  38.     SList->Print();
  39.  
  40.     std::cout << std::endl;
  41.  
  42.  
  43.     /**
  44.      * Sorted List ITEM DELETION:
  45.      *
  46.      * NOTE:
  47.      * Without the decrement of the index value, inside the nested loop, in the SortedList::DeleteItem
  48.      * method, only the first occurrence of the following supplied value would be deleted.
  49.      */
  50.     SList->DeleteItem(1.5);
  51.  
  52.  
  53.     /**
  54.      * Sorted List ITEM OUTPUT:
  55.      */
  56.     SList->Print();
  57.  
  58.     std::cout << std::endl;
  59.  
  60.  
  61.     /**
  62.      * Sorted List ITEM INSERTION:
  63.      */
  64.     SList->InsertItem(2.5);
  65.  
  66.  
  67.     /**
  68.      * Sorted List ITEM OUTPUT:
  69.      */
  70.     SList->Print();
  71.  
  72.     std::cout << std::endl;
  73.  
  74.  
  75.     /**
  76.      * Sorted List ITEM DELETION:
  77.      *
  78.      * NOTE:
  79.      * Without the decrement of the index value, inside the nested loop, in the SortedList::DeleteItem
  80.      * method, only the first occurrence of the following supplied value would be deleted.
  81.      */
  82.     SList->DeleteItem(2.5);
  83.  
  84.  
  85.     /**
  86.      * Sorted List ITEM OUTPUT:
  87.      */
  88.     SList->Print();
  89.  
  90.     std::cout << std::endl;
  91.  
  92.  
  93.     /**
  94.      * Another fundamental benefit of using pointers in C++, is the program's ability to clean them
  95.      * out of memory when it is finished using them.
  96.      */
  97.     delete SList;
  98.  
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment