On the C ++ STL stack container

On the C ++ STL stack container

Benpian brief essay \ (C ++ STL \) in \ (stack \) to use containers and common tips.

The concept stack container

\ (stack \) is the stack of meaning in English. Stack is a basic data structure. The \ (C ++ STL \) in the stack is to such a data structure of the template.
A schematic view of the stack as follows: This is the data structure of an advanced out. This is very important! !

In fact, \ (Stack \) container is not a standard data structure, it is actually a container adapter , which can also store other \ (STL \) container. But that use too advanced and not very common, so this does not introduce. Interested readers seek information on their own.

Statement stack container

\ (stack \) container stored in the template library: #include<stack>Lane, before using the need to open the library.
\ (stack \) declared the vessel follows the \ (C ++ STL \) of the general statement of principle:
the type of container <variable type> Name
Example:

#include<stack>
stack<int> st;
stack<char> st;
stack<pair<int,int> > st;
stack<node> st;
struct node{...};

The method of using a container stack

\ (Stack \) to use a container substantially as shown in the table:
| usage | effect |
| ------------------------ | ---- ------------------------------ |
| st.top()| return stack of stack elements |
| st.push()| join a stack from the top element |
| st.size()| returns the current stack length (size) |
| st.pop()| eject a stack from the stack of elements |
| st.empty()| whether the return stack is empty, an empty, not empty 0 |

Guess you like

Origin www.cnblogs.com/fusiwei/p/11822960.html