栈
头文件写:#include<stack>
定义: stack <类型> 栈的名称;
push()进栈
pop()出栈顶
size()栈的大小...栈的元素个数
empty()判空...1为空,0为非空
代码如下
#include <bits/stdc++.h>
#include <stack>
using namespace std;
int main()
{
stack<int> stack1;
stack1.push(5);
stack1.push(2);
stack1.push(1);
cout<<stack1.top()<<endl;
cout<<stack1.empty()<<endl;//==0 不为空
cout<<stack1.size()<<endl;
stack1.pop();
cout<<stack1.top()<<endl;
cout<<stack1.empty()<<endl;//==0 不为空
cout<<stack1.size()<<endl;
return 0;
}