#include <iostream>#include <queue>usingnamespacestd;classStack{intsize=0;queue<int>q1;queue<int>q2;public:// Push element x onto stack.voidpush(intx){if(empty()||!q1.empty()){q1.push(x);}else{q2.push(x);}size++;}// Removes the element on top of the stack.voidpop(){if(!q1.empty()){while(q1.size()>1){inta=q1.front();q1.pop();q2.push(a);}q1.pop();}else{while(q2.size()>1){inta=q2.front();q2.pop();q1.push(a);}q2.pop();}size--;}// Get the top element.inttop(){if(!q1.empty()){returnq1.back();}else{returnq2.back();}}// Return whether the stack is empty.boolempty(){if(size==0){returntrue;}else{returnfalse;}}};