用两个栈来实现一个队列,完成队列的Push和Pop操作。
public class StackQueue {
Stack<String> stack = new Stack<>();
Stack<String> stack2 = new Stack<>();
public void push(String content) {
stack.push(content);
}
public String pop() {
if (stack2.empty()) {
while (!stack.empty())
stack2.push(stack.pop());
}
return stack2.pop();
}
}