首先是栈的基本操作,也就这些了
#include <bits/stdc++.h>
using namespace std;
int main ()
{
stack<int> test;//声明方式:stack <数据类型> 名称
test.push(2); //向栈中压入2
test.top()=1; //也可以直接改变栈顶的值
test.pop(); //弹出栈顶部的值
if (test.empty())//如果栈空,返回true
cout<<"空栈";
cout<<test.size();//返回栈中元素数目
return 0;
}
来源:https://www.cnblogs.com/Salty-Fish/p/12310903.html