The first time I saw a stack, I thought it was a container with the same status as a vector, not actually
Official explanation: Stacks is a type of container adaptor, specifically designed to a LIFO context (last-in-first-out), where elements ar e inserted and extracted only from one end of the container
In fact, when our phone is charging, the big guy that connects the USB port and Jack is the adapter. Essentially, an adapter is a mechanism that makes something behave as if it were something else.
Put an example of a stack application first:
1#include <iostream>2#include <stack>3 4 using namespacestd;5 6 intMain ()7 {8stack<int>IntStack;9 for(size_t i =0; I! =Ten; i++)Ten Intstack.push (i); One while(!intstack.empty) { A intval = Intstack.top ();//returns the top element of the stack, but does not eject -cout <<Val; -Intstack.pop ();//pops the top of the stack element, but does not return the element value the } -cout <<Endl; - return 0; -}Seg_container_adaptor_stack
C + + Sequential container Adapter