class MyStack { // Push element x onto stack. Queue<Integer> queue = new LinkedList<Integer>(); public void push(int x) { Queue<Integer> q = new LinkedList<Integer>(); q.offer(x); while (!queue.isEmpty()) { q.offer(queue.poll()); } queue = q; } // Removes the element on top of the stack. public void pop() { queue.poll(); } // Get the top element. public int top() { return queue.peek(); } // Return whether the stack is empty. public boolean empty() { return queue.isEmpty(); } }