(1) To use the stack, you must include the header file <stack >:# include <stack> (2) the stack definition in the header file is as follows: namespace std {template <class T, class Container = deque <T> class stack;} The first template parameter represents the element type. The second parameter with the default value is used to define the actual Container for storing elements in the stack, deque is used by default. Deque is used instead of vector because deque releases the memory when removing elements and does not have to copy all elements during reallocation. In fact, stack simply converts operations into the corresponding calls of internal containers. You can use any sequential container to support stacks, as long as they support back (), push_back (), pop_back () and other actions. (3) stack operations: stack () default constructor generates an empty stackexplicit stack: stack (const Container & cont) to generate a stack, take the element in the cont of the container as the initial value (copy) size_type stack: size () const to return the number of elements bool stack: empty () const to determine whether the stack is empty void stack :: push (const value_type & elem) inserts a copy of elem into the stack to create the first element value_type & stack: top () const value_type & stack: top () const returns the top element of the stack. The caller must ensure that the stack is not empty. Otherwise, it may be undefined. void stack: pop () removes the top element of the stack, the caller must ensure that the stack is not empty. Otherwise It may be an undefined action. bool comparison (const stack & st1, const stack & st2) returns the comparison results of two identical stacks. comparison can be one of the following operations: operator =, operator! =, Operator <, operator>, operator <=, operator> =