import java.util.Stack;
/**
入队:将元素进栈stack1
出队:判断栈stack2是否为空。
如果stack2为空,则将栈stack1中所有元素pop,并push进栈stack2,然后栈stack2出栈,实现“stack1中的先进,从stack2先出”。
如果stack2不为空,栈stack2直接出栈;等到stack2为空时,再重复上述操作。
*/
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() {
if(stack2.empty()){
if(stack1.empty()){
return -1;
}
while(!stack1.empty()){
stack2.push(stack1.pop());
}
}
return stack2.pop();
}
}