y

class Stack {

```
Queue<Integer> queue1 = new LinkedList<Integer>();
Queue<Integer> queue2 = new LinkedList<Integer>();
// Push element x onto stack.
public void push(int x) {
while (!queue1.isEmpty()) {
int num = queue1.poll();
queue2.add(num);
}
queue1.add(x);
}
// Removes the element on top of the stack.
public void pop() {
if (!queue1.isEmpty()) {
queue1.poll();
return;
}
while (queue2.size() != 1) {
int num = queue2.poll();
queue1.add(num);
}
queue2.poll();
}
// Get the top element.
public int top() {
if (!queue1.isEmpty()) {
return queue1.peek();
}
while (queue2.size() != 1) {
int num = queue2.poll();
queue1.add(num);
}
int num = queue2.poll();
queue1.add(num);
return num;
}
// Return whether the stack is empty.
public boolean empty() {
return queue1.isEmpty() && queue2.isEmpty();
}
```

}