#include<vector>
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main()
{
stack<int> s;
s.push(1); // void push(T t);压栈存入数据
s.push(2);
s.push(3);
int result = s.top(); // T top();只输出第一个顶部数据,不弹栈
int result2 = s.top();//result=result2由于top的使用特性
s.pop(); // void pop();弹栈存入数据
int result3 = s.top();
cout << s.empty() << endl;
int sz = s.size();
cout << result << " " << result2 << " " << result3 << endl;
}
stack(栈)几个函数的用法
最新推荐文章于 2024-07-27 21:27:02 发布