用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型

public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
Stack<Integer> stack = new Stack<Integer>();
stack.push(3);
stack.push(2);
stack.push(4);
Stack<Integer> stack2 = new Stack<Integer>();
while (!stack.empty()) {
stack2.push(stack.pop());
}
while (!stack2.isEmpty()) {
list.add(stack2.pop());
}
for (int i : list) {
System.out.println(i);
}
}

猜你喜欢

转载自blog.csdn.net/qq_21406125/article/details/80238748