Implement Queue using Stacks LeetCode solution in C++
1class MyQueue {2public:3stack<int> s1;4stack<int> s2;56MyQueue() {}78void push(int x) {9s1.push(x);10}1112int pop() {13if (s1.empty() && s2.empty()) return -1;14while (s2.empty()) {15while (!s1.empty()) {16s2.push(s1.top());17s1.pop();18}19}20int x = s2.top();21s2.pop();22return x;23}2425int peek() {26if (!s2.empty()) {27return s2.top();28} else {29while (!s1.empty()) {30int val = s1.top();31s2.push(val);32s1.pop();33}34return s2.top();35}36}3738bool empty() {39if (s1.empty() && s2.empty()) {40return true;41}42return false;43}44};4546/**47* Your MyQueue object will be instantiated and called as such:48* MyQueue* obj = new MyQueue();49* obj->push(x);50* int param_2 = obj->pop();51* int param_3 = obj->peek();52* bool param_4 = obj->empty();53*/