两个栈实现队列
来源:互联网 发布:js获取当前日期时间 编辑:程序博客网 时间:2024/06/16 04:27
import java.util.Stack;
public class Solution {
Stack<Integer> stack1 = new Stack<Integer>();
Stack<Integer> stack2 = new Stack<Integer>();
public void push(int node) {
while(!stack2.isEmpty()){
stack1.push(stack2.pop());
}
stack1.push(node);
}
public int pop() {
while(!stack1.isEmpty()){
stack2.push(stack1.pop());
}
return stack2.pop();
}
public class Solution {
Stack<Integer> stack1 = new Stack<Integer>();
Stack<Integer> stack2 = new Stack<Integer>();
public void push(int node) {
while(!stack2.isEmpty()){
stack1.push(stack2.pop());
}
stack1.push(node);
}
public int pop() {
while(!stack1.isEmpty()){
stack2.push(stack1.pop());
}
return stack2.pop();
}
}
完成!
阅读全文
0 0
- 两个栈实现队列
- 两个队列实现栈
- 两个栈实现队列
- 两个栈实现队列
- 两个栈实现队列
- 两个队列实现栈
- 两个栈实现队列
- 两个 栈 实现队列
- 两个栈实现队列
- 两个队列实现栈
- 两个栈实现队列
- 两个栈实现队列
- 两个队列实现栈
- 两个栈实现队列
- 两个栈实现队列
- 两个栈实现队列
- 队列--两个栈实现
- 两个队列实现栈
- 单核1G内存的云服务器可以用来做些什么?
- JS中的全局变量和局部变量,和声明提升
- leetcode hard专杀之84. Largest Rectangle in Histogram
- bzoj1015: [JSOI2008]星球大战starwar(并查集)
- 一个请假案例弄懂责任链模式
- 两个栈实现队列
- 谈谈进程与线程
- 经典算法学习-循坏赛日程表-分治|递推|压位lowbit
- PHP -- 微信公众号支付(H5支付)
- js之onreadystatechange事件
- 数据结构与算法(Python)-Python快速入门篇4
- 基于SuperMap的Echarts迁徙图
- 简单记录Tensorflow中Graph和Session的关系
- Ubuntu14.04 LTS 安装libboost1.55