一、基本概念
1、stack容器是一种先进后出的数据结构,它只有一个出口。
2、栈容器可以判断是否为空。
3、stack容器提供的接口
二、基本用法
#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
using namespace std;
void Test01()
{
stack<int>s;
// 入栈
s.push(10);
s.push(20);
s.push(30);
s.push(40);
// 只要栈不为空,就执行出栈操作,查看栈顶
while (!s.empty())
{
//查看栈顶元素
cout << "栈顶元素为:" << s.top() << endl;
// 出栈操作
s.pop();
}
cout << "栈的大小为:" << s.size() << endl;
}
int main()
{
Test01();
cin.get();
}