Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. template<typename T, typename C = deque<T> >
  2. class Stack {
  3. private:
  4. C _c;
  5.  
  6. public:
  7. Stack() :
  8. _c ()
  9. {}
  10.  
  11. Stack(const C& c) : _c(c) {}
  12.  
  13. Stack(initializer_list<T> rhs) : _c(rhs) {}
  14.  
  15. Stack (const Stack& rhs) : _c(rhs._c) {}
  16.  
  17. Stack (Stack&& rhs) {
  18. swap(rhs);
  19. }
  20.  
  21. Stack& operator = (const Stack& other) {
  22. if (this == &other)
  23. return *this;
  24. Stack that(other);
  25. swap(that);
  26. return *this;
  27. }
  28.  
  29. Stack& operator = (Stack&& other) {
  30. if (this == &other)
  31. return *this;
  32. Stack that(move(other));
  33. swap(that);
  34. return *this;
  35. }
  36.  
  37. void push(const T& v) {
  38. _c.push_back(v);
  39. }
  40.  
  41. void pop() {
  42. _c.pop_back();
  43. }
  44.  
  45. T& top() {
  46. return _c.back();
  47. }
  48.  
  49.  
  50. bool empty() const {
  51. return _c.size() == 0;
  52. }
  53.  
  54. int size() const {
  55. return _c.size();
  56. }
  57.  
  58. void swap (Stack& rhs) {
  59. std::swap(_c, rhs._c);
  60. }
  61. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement