一、思路分析
首先准备两个栈,用 static1 来入队列,用 static2 来出队列
入队列:先把 static2 中的所有元素加入到 static1 中,然后往 static1 中入栈
出队列:将 static1 中的所有元素加入到 static2 中,然后 static2 进行出栈操作
取队首元素:将 static1 中的所有元素加入到 static2 中,然后对 static2 取栈顶元素
二、代码
import java.util.Stack;
public class TestQueue {
Stack<Integer> stack1 = new Stack<Integer>(); // 用来入队列
Stack<Integer> stack2 = new Stack<Integer>()