Implement stack using queues

problem [https://leetcode.com/problems/implement-stack-using-queues/ 225. ].

Problem description
Implement a last in first out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal queue (, ,  , and  ).

Implement the  class:
 * Pushes element x to the top of the stack.
 * Removes the element on the top of the stack and returns it.
 * Returns the element on the top of the stack.
 * Returns  if the stack is empty,   otherwise.


 * Notes:
 * You must use only standard operations of a queue, which means only,  ,  , and   operations are valid.
 * Depending on your language, the queue may not be supported natively. You may simulate a queue using a list or deque (double-ended queue), as long as you use only a queue's standard operations.


 * Example 1
 * Input


 * Output
 * [null, null, null, 2, 2, false]


 * Explanation


 * Constraints
 * At most  calls will be made to ,  ,  , and.
 * All the calls to  and   are valid.
 * All the calls to  and   are valid.


 * Follow-up: Can you implement the stack such that each operation is amortized  time complexity? In other words, performing   operations will take overall   time even if one of those operations may take longer. You can use more than two queues.

Approach 1: using two queues
One basic approach is to use two queues: queue 1 and queue 2.

At least one of the two queues must be empty at any moment.

So the space complexity is O(n).


 * Push
 * If both queues are empty, push to queue 1.
 * Otherwise, push to the stack that is non-empty.
 * The time complexity for this is O(1).


 * Pop
 * If both queues are empty, then do nothing.
 * Otherwise, pick the queue that is non-empty, and do the following:
 * Pull off all elements but the first element from the non-empty queue, and push these elements to the other queue, preserving the order.
 * Pop the last element from the original queue. This becomes the return value (i.e. the top element of the stack, from the user's perspective).
 * The time complexity for this is O(n), where n is the number of total elements in the data.


 * Top
 * 1) First, do the same thing as in the pop operation. Get the top value of the stack.
 * 2) * After this step, elements must have been transferred from the original non-empty queue to the other queue.
 * 3) Insert back this top value into the non-empty queue.
 * The time complexity for this is O(n), where n is the number of total elements in the data. This is the same as in the pop operation.


 * Empty
 * We just need to check if both queues are empty.
 * The time complexity for this is O(1).

C++

 * 
 * In C++ queues, elements are pushed at the back and popped from the front.
 * In C++ the method has return type  . Hence it cannot be used to retrieve the top value.

Java

 * implementation classes:
 * 
 * 
 * Allowed methods in this problem:
 * Insert at the end:  /
 * Pop from the front:  /