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

#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 容器是一种栈的结构, 先进后出,不支持遍历,没有迭代器

发布了105 篇原创文章 · 获赞 6 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43903378/article/details/104079417