Ch3-5: implement myqueue with 2 stacks
来源:互联网 发布:拼图软件哪个好四宫格 编辑:程序博客网 时间:2024/05/21 08:59
since Stack is LIFO, Queue is FIFO;
in order to implement LIFO, need to have a stack1 to buff the data and back to stack2 for pop. it is just like cooling the hot water with 2 cups, it can reverse the order.
But one thing need to notice. we only reverse the order if we have no water in stack2 for drink. so only in pushing, we directly pour water in stack1. Other cases, we need to check if stack2 is empty so as to reverse hot water in stack1 to 2.
It save time.
Output:
Executing the program....$demo 0 91 1010 0
0 0
- Ch3-5: implement myqueue with 2 stacks
- Q3.5 Implement a MyQueue class which implements a queue using two stacks.
- Ch3-2: implement min() for a stack with O(1)
- Ch3-1: use a single array to implement three stacks.
- Implement Queue with Two Stacks
- 【17】Implement a MyQueue class which implements a queue using two stacks
- Implement Queue with two Stacks Java
- 2 stacks implement a queue
- MyQueue
- Implement Queue using Stacks
- Implement Queue using Stacks
- Implement Queue using Stacks
- Implement Queue using Stacks
- Implement Queue using Stacks
- Implement Queue using Stacks
- Implement Queue using Stacks
- Implement Queue using Stacks
- Implement Queue using Stacks
- HTML5 Web 存储d
- OSG QWidgetImage 的使用
- 去掉Visual Studio 2005的IntelliSense功能
- POJ 1008
- 外观模式
- Ch3-5: implement myqueue with 2 stacks
- liunx系统安装nginx,以及配置、用到的简单指令
- Sql Server 中的 自定义函数
- Android Binder设计与实现 – 设计篇
- Oracle RAC检查工具raccheck
- sscanf的高级用法
- 从devstack开始 学习openstack
- HQL: Hibernate查询语言
- Java中的内部类和匿名类