Stack (C++)
Appearance
	
	
A stack is a standard C++ container adaptor, designed to be used in a LIFO context[1], and is implemented as an interface/wrapper to the type passed to it as a template argument, which defaults to a deque.[2] It is so simple, that it can be described just by an sample interface:
| C++ Standard Library | 
|---|
| Containers | 
| C standard library | 
template<class T, Class C = deque<T> >
class std::stack {
protected:
C c;
public:
typedef typename C::value_type value_type;
typedef typename C::size_type size_type;
typedef C container_type;
explicit stack(const C& a = C()) : c(a){} // Inherit the constructor
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
value_type& top() const { return c.back(); }
const value_type& top() const { return c.back(); }
void push(const value_type& n) { c.push_back(n); }
void pop() { c.pop_back(); }
};
Overview of Functions
| Function | Description | ||
|---|---|---|---|
| Element Access | top | Returns a reference to the top element of the stack, does not pop it | |
| Modifiers | push | Push an element onto the stack | pop || Pop top element off stack || | 
| size | Return number of elements in stack | 
References
- ^ "stack - C++ Reference". cplusplus.com. Retrieved 25 April 2013.
- ^ Stroustrup, Bjarne (1997). C++ Programming Language. Addison-Wesley. pp. 475โ476. ISBN 0201889544.
- ^ Stroustrup, Bjarne (1997). C++ Programming Language. Addison-Wesley. p. 475. ISBN 0201889544.
| This redirect has not been added to any content categories. Please help out by adding categories to it so that it can be listed with similar redirects. (April 2013) | 
 
	