前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >STL_stack

STL_stack

作者头像
GeekLiHua
发布2025-01-21 13:51:44
发布2025-01-21 13:51:44
7500
代码可运行
举报
文章被收录于专栏:JavaJava
运行总次数:0
代码可运行

STL_stack

简介:本文通过一段代码,教大家学会stack的使用。

stack容器基本概念

stack常用接口

学习代码:

代码语言:javascript
代码运行次数:0
复制
#include<iostream>
#include<stack>

using namespace std;

// Stack container

void test01()
{
	// Features: in line with the first in and out
	// 栈的特性:栈是一种后进先出的数据结构
	stack<int> s;  // default contruction

	// push
	// 往栈里面放入元素
	s.push(10);
	s.push(20);
	s.push(30);
	s.push(40);
	cout << "栈的大小:" << s.size() << endl;
	// As long as the stack is not empty, check the stack and  execute the stack operation
	while (!s.empty())
	{
		// View top of stack elements
		// 查看栈顶元素
		cout << "栈顶元素为:" << s.top() << endl;

		// pop
		// 出栈
		s.pop();
	}
	cout << "栈的大小:" << s.size() << endl;


}

int main()
{
	test01();
	return 0;
}

运行结果

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-01-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • STL_stack
    • stack容器基本概念
    • stack常用接口
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档