The STL stack is a container adapter that represents a last-in, first-out (LIFO) stack. Only the most-recently inserted element in the stack can be accessed.
stack is a container adapter, not a true STL container, and is implemented in terms of another linear container class like vector or deque. To explicitly specify which container to use in the stack, parametrize the stack as stack<T, ContainerType<T> >.
Pushes a new element onto the stack.
Removes the top element of the stack. The behavior is undefined if the stack has no elements, so be sure not to pop off of an empty stack. Note that pop does not return a value; use top to get the value before popping.
Returns the top element of the stack. The behavior is undefined if the stack has no elements, so be sure not to access the top element of an empty stack. The top function returns a reference to the top element of the stack, and you can modify the element if you so choose.
Returns the number of elements stored in the stack.
Returns whether the stack is empty. It's considered good practice to call empty to determine whether the stack is empty rather than checking whether size() returns zero.
stack around an existing container.Constructs a new stack whose contents are equal to those of the specified container. This constructor is rarely used, but is useful if you already have the data you want to use in the stack.