/** Initialize your data structure here. */ stack<int>st1; stack<int>st2; MyQueue() {
}
/** Push element x to the back of queue. */ voidpush(int x){ if(st2.empty()) { st1.push(x); } else { while(!st2.empty()) { st1.push(st2.top()); st2.pop(); } st1.push(x); } }
/** Removes the element from in front of queue and returns that element. */ intpop(){ while(!st1.empty()) { st2.push(st1.top()); st1.pop(); } int popElement = st2.top(); st2.pop(); return popElement; }
/** Get the front element. */ intpeek(){ while(!st1.empty()) { st2.push(st1.top()); st1.pop(); } return st2.top(); }
/** Returns whether the queue is empty. */ boolempty(){ if(st1.empty() && st2.empty()) returntrue; else returnfalse; }