Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T, typename C = deque<T> >
- class Stack {
- private:
- C _c;
- public:
- Stack() :
- _c ()
- {}
- Stack(const C& c) : _c(c) {}
- Stack(initializer_list<T> rhs) : _c(rhs) {}
- Stack (const Stack& rhs) : _c(rhs._c) {}
- Stack (Stack&& rhs) {
- swap(rhs);
- }
- Stack& operator = (const Stack& other) {
- if (this == &other)
- return *this;
- Stack that(other);
- swap(that);
- return *this;
- }
- Stack& operator = (Stack&& other) {
- if (this == &other)
- return *this;
- Stack that(move(other));
- swap(that);
- return *this;
- }
- void push(const T& v) {
- _c.push_back(v);
- }
- void pop() {
- _c.pop_back();
- }
- T& top() {
- return _c.back();
- }
- bool empty() const {
- return _c.size() == 0;
- }
- int size() const {
- return _c.size();
- }
- void swap (Stack& rhs) {
- std::swap(_c, rhs._c);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement