Implement Stack using Queues LeetCode solution in C++
1class MyStack {2public:3/** Initialize your data structure here. */4queue<int> q1;5MyStack() {}67/** Push element x onto stack. */8void push(int x) {9int sz = q1.size();10q1.push(x);11while (sz--) {12q1.push(q1.front());13q1.pop();14}15}1617/** Removes the element on top of the stack and returns that element. */18int pop() {19int result = top();20q1.pop();21return result;22}2324/** Get the top element. */25int top() {26return q1.front();27}2829/** Returns whether the stack is empty. */30bool empty() {31return q1.empty();32}33};