用两个栈实现队列
来源:互联网 发布:3ds淘宝哪家店没问题 编辑:程序博客网 时间:2024/06/07 03:06
用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
import java.util.Stack;public class Solution { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Integer>(); public void push(int node) { stack1.push(new Integer(node)); } public int pop() { if(stack2.empty()){ while(!stack1.empty()){ stack2.push(stack1.pop()); } } if(stack2.empty()) System.out.println("stack1 is empty!"); return stack2.pop().intValue(); } }
0 0
- 用两个栈实现队列 & 用两个队列实现栈
- 用两个队列实现栈&用两个栈实现队列
- 用两个栈实现队列 & 两个队列实现一个栈
- 两个栈实现队列&&用两个队列实现一个栈
- 用两个栈实现队列 & 两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- ACM-ICPC国际大学生程序设计竞赛长春赛区(2015)地区赛有感
- UVALive 7003 A Balance Game on Trees 树形dp
- Fedora 12无法联网情况下安装gcc
- UI - RequestNetWork
- bzoj1642[Usaco2007 Nov]Milking Time 挤奶时间
- 用两个栈实现队列
- 在有序但是含有空的字符串中查找最左边特定字符串的位置
- 【四】GlusterFS管理员手册
- 秒针国家统计局项目:我的一些感想和8点安全措施
- 数据库连接池DBPool分析(八):redis连接池 redis_connection_pool
- free指针时的_CrtIsValidHeapPointer问题
- eclipse主题与字体设置
- 数据库备份与恢复
- Android 多线程处理之多线程用法大集合