class MyQueue {
public:
MyQueue() {
}
void push(int x) {
std::stack temp_stack;
while(!_data.empty()){
temp_stack.push(_data.top());
_data.pop();
}
temp_stack.push(x);
while(!temp_stack.empty()){
_data.push(temp_stack.top());
temp_stack.pop();
}
}
int pop() {
int x = _data.top();
_data.pop();
return x;
}
int peek() {
return _data.top();
}
bool empty() {
return _data.empty();
}
private:
std::stack _data;
};
leetcode_栈队列堆_232_栈实现队列的操作方法
最新推荐文章于 2024-08-19 09:12:14 发布