C++ STL 容器之stack简单使用

拜拜、爱过 提交于 2020-01-24 13:08:06
#include <iostream>
#include <stack>
#include <string>
using namespace std;
void test1() {
	stack<int> s;
	s.push(10);
	s.push(20);
	s.push(30);
	while (s.size())	{
		cout << "stack top is" << s.top() << endl; // 栈顶
		s.pop();  // 出栈
	}
}
int main()
{
	test1();
	return 0;
}

stack 容器是一种栈的结构, 先进后出,不支持遍历,没有迭代器
stack 不支持排序

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!