class MyQueue {
private:
stack[HTML_REMOVED] in, out;
void in2out() {
while (!in.empty()) {
out.push(in.top());
in.pop();
}
}
public:
/* Initialize your data structure here. /
MyQueue() {}
/** Push element x to the back of queue. */
void push(int x) {
in.push(x);
}
/** 将队首的元素弹出,并返回该元素 */
int pop() {
if(out.empty()){
in2out();
}
int res = out.top();
out.pop();
return res;
}
/** 返回队首元素 */
int peek() {
if(out.empty()){
in2out();
}
return out.top();
}
/** 返回队列是否为空 */
bool empty() {
return in.empty() && out.empty();
}
};
/*
* Your MyQueue object will be instantiated and called as such:
* MyQueue obj = MyQueue();
* obj.push(x);
* int param_2 = obj.pop();
* int param_3 = obj.peek();
* bool param_4 = obj.empty();
/