暴力做法 is OK
class MyQueue {
public:
/** Initialize your data structure here. */
stack<int> st, b;
MyQueue() {
}
/** Push element x to the back of queue. */
void push(int x) {
st.push(x);
}
void copy(stack<int> &a, stack<int> &b) {
while (a.size()) {
b.push(a.top());
a.pop();
}
}
/** Removes the element from in front of queue and returns that element. */
int pop() {
copy(st, b);
int res = b.top();
b.pop();
copy(b, st);
return res;
}
/** Get the front element. */
int peek() {
copy(st, b);
int res = b.top();
copy(b, st);
return res;
}
/** Returns whether the queue is empty. */
bool empty() {
return st.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();
*/