用两个栈实现队列
来源:互联网 发布:日本原单淘宝店 编辑:程序博客网 时间:2024/05/19 18:12
题目描述:
用两个栈来实现一个队列,完成队列的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(node); } public int pop() { while(!stack1.isEmpty()){ stack2.push(stack1.pop()); } int first=stack2.pop(); while(!stack2.isEmpty()){ stack1.push(stack2.pop()); } return first; }}
阅读全文
0 0
- 用两个栈实现队列 & 用两个队列实现栈
- 用两个队列实现栈&用两个栈实现队列
- 用两个栈实现队列 & 两个队列实现一个栈
- 两个栈实现队列&&用两个队列实现一个栈
- 用两个栈实现队列 & 两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- cookie与session的区别与联系
- Android ContentProvider启动流程源码解析(8.0)
- 通过php-fpm status判断pm.max_childern的值应该设置为多少
- Angular2学习笔记1
- MySQL数据备份和还原
- 用两个栈实现队列
- Java线程池机制源码分析
- 数据库连接池c3p0和dbcp
- Manacher算法——找字符串最长的回文子串
- hdu1305(字典树)
- fisher线性判别
- php编程注意点
- 浅谈电子商务网站购物车
- 棱镜门事件-引人深思IT技术发展的道德伦理问题