import java.util.Stack; class MyQueue { private Stack stack1; private Stack stack2; public MyQueue() { stack1 = new Stack<>(); stack2 = new Stack<>(); } public void push(int x) { stack1.push(x); } public int pop() { if(stack2.isEmpty()){ transferToStack2(); } return stack2.pop(); } public int peek() { if(stack2.isEmpty()){ transferToStack2(); } return stack2.peek(); } public boolean empty() { return stack1.isEmpty() && stack2.isEmpty(); } public void transferToStack2(){ while(!stack1.isEmpty()){ stack2.push(stack1.pop()); } } }