Recently began to do interview questions, which involved a lot of C + + basic data structure, this review.
The content of this blog is simple, from the Chao_xun blog, I will share it for study and research only, not assume any legal responsibility.
The following is a content reference:
C++stack (Stack) is an adaptation of a container that implements an advanced data structure (FILO).
You need to include the #include header file when using the container;
The sample code that defines the stack object is as follows:
STACKS1;
STACKS2;
The basic operations of stack are:
1. Into the stack: such as S.push (x);
2. Out stack: such as S.pop (). Note: The stack operation simply deletes the element at the top of the stack and does not return it.
3. Access to the top of the stack: such as s.top ();
4. Judge stack empty: such as S.empty (). Returns True when the stack is empty.
5. Access to the number of elements in the stack, such as s.size ();
Here's a simple example:
#include <iostream>
#include <stack>
using namespace std;
int main (void)
{
stack<double>s;//defines a stack for
(int i=0;i<10;i++)
s.push (i);
while (!s.empty ())
{
printf ("%lf\n", S.top ());
S.pop ();
}
cout<< "The number of elements in the stack is:" <<s.size () <<endl;
return 0;
}