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中即可
stack1.push(node);
}
//出对列的实现方法
public int pop() {
//判断stack1是否为空,不为空,则stack1出栈,放到stack2中
while(!stack1.isEmpty()){
stack2.push(stack1.pop());
}
//stack2的栈尾正好是stack1的栈底,取得队列的头一个元素
int first = stack2.pop();
//为啥要做这个操作呢,因为如果再有元素进队列,如果不把元素移回去,有元素进入,就不是队列
//好比做事情,看到成功,还有善后工作
while(!stack2.isEmpty()){
stack1.push(stack2.pop());
}
return first;
}
}