Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty).

Implement the MyStack class:


	void push(int x) Pushes element x to the top of the stack.
	int pop() Removes the element on the top of the stack and returns it.
	int top() Returns the element on the top of the stack.
	boolean empty() Returns true if the stack is empty, false otherwise.


Notes:


	You must use only standard operations of a queue, which means that only push to back, peek/pop from front, size and is empty 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.


&nbsp;
Example 1:

Input
["MyStack", "push", "push", "top", "pop", "empty"]
[[], [1], [2], [], [], []]
Output
[null, null, null, 2, 2, false]

Explanation
MyStack myStack = new MyStack();
myStack.push(1);
myStack.push(2);
myStack.top(); // return 2
myStack.pop(); // return 2
myStack.empty(); // return False


&nbsp;
Constraints:


	1 &lt;= x &lt;= 9
	At most 100 calls will be made to push, pop, top, and empty.
	All the calls to pop and top are valid.


&nbsp;
Follow-up: Can you implement the stack using only one queue?

class MyStack:

    def __init__(self):
        self.q1 = deque()
        self.q2 = deque()

    def push(self, x: int) -> None:
        self.q1.append(x)

    def pop(self) -> int:
        while len(self.q1) > 1:
            self.q2.append(self.q1.popleft())
        
        popped_element = self.q1.popleft()
        
        # Swap q1 and q2
        self.q1, self.q2 = self.q2, self.q1
        
        return popped_element

    def top(self) -> int:
        while len(self.q1) > 1:
            self.q2.append(self.q1.popleft())
        
        top_element = self.q1[0]
        
        self.q2.append(self.q1.popleft())
        
        # Swap q1 and q2
        self.q1, self.q2 = self.q2, self.q1
        
        return top_element

    def empty(self) -> bool:
        return len(self.q1) == 0
class MyStack {

    Queue<Integer> queue = null;

    public MyStack() {
        queue = new LinkedList<>();
    }

    public void push(int x) {

        Queue<Integer> tempQueue = new LinkedList<>();
        tempQueue.add(x);

        while(!queue.isEmpty()){
         tempQueue.add(queue.remove());
        }

        queue = tempQueue;

    }

    public int pop() {
       return queue.remove();
    }

    public int top() {
        return queue.peek();
    }

    public boolean empty() {
        return queue.isEmpty();
    }
}
class MyStack {
public:
    queue<int> q1;
    queue<int> q2;
    MyStack() {

    }

    void push(int x) {
        q1.push(x);
    }

    int pop() {

        while(q1.size() !=1){
         int temp = q1.front();
            q1.pop();
            q2.push(temp);
        }
        int temp = q1.front();
        q1.pop();
        while(!q2.empty()){
            int tp = q2.front();
            q2.pop();
            q1.push(tp);
        }
        return temp;
    }

    int top() {
        while(q1.size() !=1){
         int temp = q1.front();
            q1.pop();
            q2.push(temp);
        }
        int temp = q1.front();
        q1.pop();
        q2.push(temp);
        while(!q2.empty()){
            int tp = q2.front();
            q2.pop();
            q1.push(tp);
        }
        return temp;
    }

    bool empty() {
        if(q1.empty()){
            return true;
        }
        return false;
    }
};

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack* obj = new MyStack();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->top();
 * bool param_4 = obj->empty();
 */
var MyStack = function() {
    this.stack = [];
};

/** 
 * @param {number} x
 * @return {void}
 */
MyStack.prototype.push = function(x) {
    this.stack.push(x);
};

/**
 * @return {number}
 */
MyStack.prototype.pop = function() {
    return this.stack.splice([this.stack.length-1], 1)
};

/**
 * @return {number}
 */
MyStack.prototype.top = function() {
     return this.stack[this.stack.length-1]
};

/**
 * @return {boolean}
 */
MyStack.prototype.empty = function() {
    return this.stack.length === 0 ? true : false;
};

/** 
 * Your MyStack object will be instantiated and called as such:
 * var obj = new MyStack()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.empty()
 */
Implement Stack using Queues