#include<iostream>
using namespace std;
#include<stack>
void test01()
{
//创建一个stack容器
stack<int>s;
//入栈
s.push(0);
s.push(10);
s.push(20);
s.push(30);
cout << "栈的大小:" << s.size() << endl;
;// 栈满足先进后出 先放进去的元素在栈的底部
//判断如果栈不为空 从顶层一个个查看栈中元素
while (s.empty()!=NULL)
{
cout << s.top() << endl;
//出栈
s.pop();
}
cout << "出栈后栈的大小:" << s.size() << endl;
}
int main()
{
test01();
return 0;
system("pause");
}
stack 栈容器的使用 满足的 数据结构是先进后出
最新推荐文章于 2023-12-12 13:16:46 发布