import java.util.Stack;
/**
* @author shy_black
* @date 2019/3/19 8:49
* @Description:
* 1.s1看做真队列,s2看为辅助队列
* 2.每次push操作时,先把s1中的元素依次放入s2中,
* 将要push的元素压入s1,最后再把s2中的元素依次压入s1中,保证了每次压入的元素在栈s1(队列)中的最低下
* 3.pop操作-->直接从是s1出队列
*/
public class 俩个栈实现队列 {
Stack<Integer> stack1 = new Stack<Integer>();
Stack<Integer> stack2 = new Stack<Integer>();
public void push(int node) {
while(!stack1.isEmpty()) {
stack2.push(stack1.pop());
}
stack1.push(node);
while(!stack2.isEmpty()) {
stack1.push(stack2.pop());
}
}
public int pop() {
return stack1.pop();
}
}