C++ stack Library
C++ stack Functions
The <stack> library has functions that let you work with stacks. A stack stores elements in LIFO order (Last In, First Out). You can only add, read and remove the element at the top.
A stack has no index numbers and no iterators, so you cannot loop through it like a vector. To read all the elements, read the top element with top(), remove it with pop(), and repeat until the stack is empty.
| Function | Description |
|---|---|
| empty() | Checks whether a stack is empty or not |
| pop() | Removes the top element of a stack |
| push() | Adds an element to the top of a stack |
| size() | Returns the number of elements in a stack |
| swap() | Swaps the contents of two stacks |
| top() | Returns the top element of a stack |