day 10 stack栈 queue | 232 225

232 Implement Queue using Stacks

⭐栈是以底层容器完成其所有的工作,对外提供统一的接口,底层容器是可插拔的(也就是说我们可以控制使用哪种容器来实现栈的功能)。
所以STL中栈往往不被归类为容器,而被归类为container adapter(容器适配器)
栈的底层实现可以是vector,deque,list 都是可以的, 主要就是数组和链表的底层实现。

  • STL 默认使用deque作为stack 和queue的容器
std::stack<int, std::vector<int> > third;  // 使用vector为底层容器的栈
std::queue<int, std::list<int>> third; // 定义以list为底层容器的队列

Two Stacks: Instack and OutStack
Instack: Just Push to the top
OutStack: Pop and Top, everytime call the two methods and out stack is empty, we pop all the elements from in stack to out stack

225.Implement Stack using Queues

Every Time We try to pop, just keep pop until only one left

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值