classMyQueue { private: stack<int> main_stack; stack<int> stack; public: /** Initialize your data structure here. */ MyQueue() {
}
/** Push element x to the back of queue. */ voidpush(int x){ while (!main_stack.empty()) { stack.push(main_stack.top()); main_stack.pop(); } stack.push(x);
while (!stack.empty()){ main_stack.push(stack.top()); stack.pop(); }
}
/** Removes the element from in front of queue and returns that element. */ intpop(){ int top = main_stack.top(); main_stack.pop(); return top; }
/** Get the front element. */ intpeek(){ return main_stack.top(); }
/** Returns whether the queue is empty. */ boolempty(){ return main_stack.empty(); } };