C ++: Introduction and use of stack


Introduction of stack

Document introduction of stack

translation:

  1. Stack is a kind of container adapter, which is specially used in the context environment with last in first out operation. Its deletion can only insert and extract elements from one end of the container.

  2. Stack is implemented as a container adapter, which encapsulates a specific class as its underlying container, and provides a set of specific member functions to access its elements, using a specific class as its underlying, element-specific container tail ( That is, the top of the stack) is pushed in and ejected.

  3. The bottom container of the stack can be any standard container class template or some other specific container classes. These container classes should support the following operations:
    empty: judge empty operation
    back: get tail element operation
    push_back: tail insert element operation
    pop_back: tail delete element operating

  4. The standard containers vector, deque, and list all meet these requirements. By default, if no specific underlying container is specified for the stack, deque is used by default.

Use of stack

Function description Interface Description
stack() Construct an empty stack
empty() Check if the stack is empty
size() Returns the number of elements in the stack
top() Return a reference to the top element of the stack
push() Push the element val into the stack
pop() Pop the element at the end of the stack
Published 152 original articles · praised 45 · 10,000+ views

Guess you like

Origin blog.csdn.net/AngelDg/article/details/105322609
Recommended