用两个栈实现队列
来源:互联网 发布:弱电网络模块 编辑:程序博客网 时间:2024/06/06 03:07
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;
}
}
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
- 用两个栈实现队列 & 用两个队列实现栈
- 用两个队列实现栈&用两个栈实现队列
- 用两个栈实现队列 & 两个队列实现一个栈
- 两个栈实现队列&&用两个队列实现一个栈
- 用两个栈实现队列 & 两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- TensorFlow MNIST LeNet 模型持久化
- Java数组的遍历与求和
- util.God -2
- 阿里物联网套件-服务端SDK学习实践(基础篇-1准备)
- cookie跨域session共享
- 用两个栈实现队列
- (149)环境立方体贴图
- lintcode(139)最接近零的子数组和
- 一张图理清楚关系型/非关系型数据库与Elasticsearch同步
- Android -- 系统网络时间更新NetworkTimeUpdateService服务解析
- linux驱动开发之字符设备--私有数据和container_of
- 【读过的书,留下的迹】深入剖析Tomcat
- Android开发之轮播图广告的实现
- LabVIEW状态机