目录
3.5.1stack 基本概念
见数据结构:栈
3.5.2stack 常用接口
#include <iostream>
#include <string>
#include <stack>
using namespace std;
void test01()
{
//特点:符合先进后出的结构
stack<int>s;
//入栈
s.push(10);
s.push(20);
s.push(30);
s.push(40);
cout << "栈的大小:" << s.size() << endl;
//只要栈不为空就查看栈顶,并执行出栈
while (!s.empty())
{
//查看栈顶元素
cout << "栈顶元素为:" << s.top() << endl;
//出战
s.pop();
}
cout << "栈的大小:" << s.size() << endl;
}
int main() {
test01();
system("pause");
}