Next : Queue, Previous : Container adaptors, Top : Table of Contents
stack
|
Container Adaptor |
Any sequence (Sequences) supporting operations back, push_back and pop_back can be used to instantiate stack. In particular, vector (Vector), list (List), and deque (Deque), can be used. |
value_type | Typedef on stack |
size_type | Typedef on stack |
bool empty () | Method on stack |
size_type size () | Method on stack |
value_type& top () | Method on stack |
void push (const value_type& x) | Method on stack |
void pop () | Method on stack |
== | Operator on stack |
< | Operator on stack |
For example, stack<vector<int> > is an integer stack made out of vector, and stack<deque<char> > is a character stack made out of deque.templateclass stack { friend bool operator==(const stack & x, const stack & y); friend bool operator<(const stack & x, const stack & y); public: typedef Container::value_type value_type; typedef Container::size_type size_type; protected: Container c; public: bool empty() const { return c.empty(); } size_type size() const { return c.size(); } value_type& top() { return c.back(); } const value_type& top() const { return c.back(); } void push(const value_type& x) { c.push_back(x); } void pop() { c.pop_back(); } }; template bool operator==(const stack & x, const stack & y) { return x.c == y.c; } template bool operator<(const stack & x, const stack & y) { return x.c < y.c; }
|