Implement Queue with Two Stacks
来源:互联网 发布:mpu9250 dmp 9轴算法 编辑:程序博客网 时间:2024/05/16 01:47
class Node {Node next;int data;}class Stack {Node top;boolean isEmpty() {return top == null;}int pop()throws Exception{if(isEmpty()) {throw new Exception("The stack is Empty");}else {int item = top.data;top = top.next;return item;}}void push(int item) {Node node = new Node();node.data =item;node.next = top;top = node;}int peek()throws Exception {if(isEmpty()) {throw new Exception("The stack is empty!");}else {return top.data;}}}class Queue{Stack stackIn = new Stack();Stack stackOut = new Stack();public void enQueue(int element) {stackIn.push(element);}public int deQueue()throws Exception {shift();return stackOut.pop();}public void shift()throws Exception {if(stackOut.isEmpty()) {while(!stackIn.isEmpty()){stackOut.push(stackIn.pop());}}}public int peek()throws Exception {shift();return stackOut.peek();}}
- Implement Queue with Two Stacks
- Implement Queue with two Stacks Java
- implement-queue-by-two-stacks
- Implement Queue by Two Stacks
- Implement Queue by Two Stacks
- Implement Queue by Two Stacks
- Implement Queue by Two Stacks
- implement a queue by using two stacks
- [刷题]Implement Queue by Two Stacks
- lintcode: Implement Queue by Two Stacks
- #40 Implement Queue by Two Stacks
- [Lintcode]Implement Queue by Two Stacks
- Implement Queue by Two Stacks 解题报告
- Lintcode 40:Implement Queue by Two Stacks
- No. 17 - Queue Implemented with Two Stacks
- implement a queue by using two stacks [No. 31]
- Lintcode40 Implement Queue by Two Stacks solution 题解
- 【LeetCode】 Implement Queue by Two Stacks用栈实现队列
- oracle命令
- 对于eclipse选择服务器的问题eclipse Cannot create a server using the selected type
- 按两次返回键退出程序
- google protobuf的应用及遇到的问题总结
- Linux设备驱动之I2C架构分析
- Implement Queue with Two Stacks
- fabric远程部署实践
- Java读取xls文件
- Android学习——打包
- 解析省市的Jason文件
- Qt解析json数据,小例子
- Linux和windows中产生相同的伪随机序列
- 记录用:关于MVC模式的一些拾遗
- Mono