public class MyQueue { private Stack<Integer> stackPush; private Stack<Integer> stackPop; public MyQueue() { stackPush = new Stack<Integer>(); stackPop = new Stack<Integer>(); } public void push(int pushInt) { stackPush.push(pushInt); dump(); } public int poll() { if (stackPop.empty() && stackPush.empty()) { throw new RuntimeException("Queue is empty!"); } dump(); return stackPop.pop(); } public int peek() { if (stackPop.empty() && stackPush.empty()) { throw new RuntimeException("Queue is empty!"); } dump(); return stackPop.peek(); } public void dump() { if (!stackPop.isEmpty()) { return; } while (!stackPush.isEmpty()) { stackPop.push(stackPush.pop()); } } }