Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include "op.hpp"
  2. #include "Div.hpp"
  3. #include "Mult.hpp"
  4. #include "Sub.hpp"
  5. #include "add.hpp"
  6. #include "pow.hpp"
  7. #include "container.hpp"
  8. #include "sort.hpp"
  9. #include <vector>
  10. #include "base.hpp"
  11. #include <algorithm>
  12.  
  13. using namespace std;
  14.  
  15. class VectorContainer: public Container
  16. {
  17. protected:
  18. vector <Base*> trees;
  19. Sort* sort_pointer;
  20. public:
  21.  
  22. VectorContainer(): sort_pointer(nullptr) {}
  23. VectorContainer(Sort* sortList): sort_pointer (nullptr)
  24. {
  25. sort_function = sortList;
  26. }
  27.  
  28. void set_sort_function(Sort* sort_function)
  29. {
  30. this->sort_function = sort_function;
  31. }
  32.  
  33. void add_element(Base* element)
  34. {
  35. trees.push_back(element);
  36. }
  37.  
  38. void print()
  39. {
  40. for (int index = 0; index < size(); ++index)
  41. {
  42. cout << trees.at(index)->stringify() << endl;
  43. }
  44. }
  45.  
  46. void sort ()
  47. {
  48. try {sort_function->sort(this);}
  49. catch (Container* container)
  50. {
  51. cout << "Exception detected" << endl;
  52. }
  53.  
  54. }
  55.  
  56. void swap (int i, int j)
  57. {
  58. Base* temp;
  59. temp = trees.at(i);
  60. trees.at(i) = trees.at(j);
  61. trees.at(j) = temp;
  62. }
  63.  
  64. Base* at(int i)
  65. {
  66. return trees.at(i);
  67. }
  68. int size()
  69. {
  70. return trees.size();
  71. }
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement