标准模板库STL中Stack参考手册

STL中的一般栈类实现为容器适配器:它使用一个容器,并让它按照指定的方式工作。栈容器不是重新创建的,它只是对已有容器做适当的调整,默认的情况下,双端队列(deque)是基础容器,但是用户可以用下面的声明选择链表或者向量

stack<int> stack1;			//默认为双端队列
stack<int, vector<int> > stack2;	//向量  两个>之间要有空格
stack<int, list<int> > stack3;	//链表


构造函数:

  #include <stack>
  stack();
  stack( const Container& con );


成员函数:

empty

true if the stack has no elements

pop

removes the top element of a stack

push

adds an element to the top of the stack

size

returns the number of items in the stack

top

returns the top element of the stack

 

中文:

成员函数

实现操作

bool empty()const

如果栈为空,则返回true,否则返回false

void pop()

移去栈的栈顶元素

void push(const T& el)

将el插入到栈的顶端

size_type size()const

返回栈中元素数目

stack()

创建一个空栈

T& top()

返回栈顶元素

const T& top() const

返回栈顶元素

 

 

 

 

 

 

 

 

 

 

 

 

注意:pop() 函数返回的是void类型,也就是说pop()不返回从栈中弹出的元素,所以如果在出栈时要保存栈顶元素,应该先用top()函数返回栈顶元素再出栈

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值