Guest User

Untitled

a guest
Jun 24th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #ifndef STACK_H_INCLUDED
  2. #define STACK_H_INCLUDED
  3.  
  4. #include <vector>
  5. using namespace std;
  6.  
  7. template<typename T>
  8. class Stack;
  9.  
  10. template<typename T>
  11. Stack<T> operator+(const Stack<T>& a, const Stack<T>& b);
  12.  
  13. template<typename T>
  14. class Stack
  15. {
  16.     private:
  17.     friend Stack<T> operator+<>(const Stack<T>& a, const Stack<T>& b);
  18.  
  19.     vector<T> data;
  20.  
  21.     public:
  22.     void printAll() { for(int a=0;a<data.size();a++) cout << data[a] << endl; cout << endl;}
  23.     Stack() {}
  24.     bool isEmpty() const { return data.empty(); }
  25.     void push(const T& item) { data.push_back(item); }
  26.     const T& top() const { return data.back(); }
  27.     T& top() { return data.back(); }
  28.     void pop() { data.pop_back(); }
  29. };
  30.  
  31. template<typename T>
  32. Stack<T> operator+(const Stack<T>& a, const Stack<T>& b)
  33. {
  34.     Stack<T> c = a;
  35.     for(int k=0;k<b.data.size();k++)
  36.         c.push(b.data[k]);
  37.  
  38.     return c;
  39. }
  40.  
  41.  
  42. #endif // STACK_H_INCLUDED
Add Comment
Please, Sign In to add comment