import java.util.Stack; //两个栈实现一个 队列,想象以下是一个队列 public class StackQuene { private Stackstack1=new Stack<>(); //作为入队类 private Stack stack2=new Stack<>(); //作为出队列 public void push(int node) { stack1.push(node); } public int pop() { if(stack2.isEmpty()) //只有当stack2为空时,才可以对stack2入栈 { while(!stack1.isEmpty()) { stack2.push(stack1.pop()); } } return stack2.pop(); } }