Advertisement
rinab333

CSCI 340 assignfive.cc

Jul 16th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. //Terina BUrr
  2. //Assignment four
  3. //due 10/18/15
  4. //section one
  5. #include <iostream>
  6. #include <vector>
  7. #include <cstdlib>
  8. #include <iomanip>
  9. #include <algorithm>
  10. #include "assignmentfive.h"
  11. using namespace std;
  12. //------------------------------------------------
  13. // Do not modify this section of code
  14. //------------------------------------------------
  15. const int MAX_SIZE = 1000;
  16. const int MAX_COUNT = 20;
  17. const int WIDTH = 5;
  18. const int ROW_SIZE = 5;
  19. int mcount = 0;
  20. int rcount = 0;
  21.  
  22. void display(int d) {
  23.     if ( mcount < MAX_COUNT ) {
  24.         cout << setw(WIDTH) << d;
  25.         mcount++;
  26.         rcount++;
  27.         if ( rcount == ROW_SIZE ) {
  28.             cout << endl;
  29.             rcount = 0;
  30.         }
  31.     }
  32. }
  33. //--------------------------------------------
  34. // End
  35. //--------------------------------------------                        
  36.                        
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //-------------------------------------------
  48. // Do not modify this section of code
  49. //-------------------------------------------
  50. #define BINTREE_MAIN
  51. #ifdef BINTREE_MAIN
  52. int main() {
  53.     vector<int> v(MAX_SIZE);    
  54.     for (int i=1; i<MAX_SIZE; i++)
  55.         v[i] = i;
  56.     random_shuffle( v.begin(), v.end() );
  57.     //mcount = rcount = 0;
  58.     //for_each( v.begin(), v.end(), display );
  59.  
  60.     binTree bt;
  61.     vector<int>::iterator it;
  62.     for (it=v.begin(); it!=v.end(); it++)
  63.         bt.insert( *it );
  64.  
  65.     cout << "Height: " << bt.height() << endl;
  66.     cout << "Size: " << bt.size() << endl;
  67.     cout << "In order traverse (displaying first " << MAX_COUNT << " numbers): " << endl;
  68.     mcount = rcount = 0;
  69.     bt.inorder( display );
  70.     cout << "\n\nPre order traverse (displaying first " << MAX_COUNT << " numbers): " << endl;
  71.     mcount = rcount = 0;
  72.     bt.preorder( display );
  73.     cout << "\n\nPost order traverse (displaying first " << MAX_COUNT << " numbers): " << endl;
  74.     mcount = rcount = 0;
  75.     bt.postorder( display );
  76.  
  77.     cout << endl;
  78.     return 0;
  79. }
  80.  
  81. #endif
  82. //---------------------------------
  83. // End
  84. //--------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement