stack容器

一、基本概念

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();
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值