描述
用队列来实现栈
解决
最简单的是用deque实现了,用一个queue也可以实现。
class Stack {
public:
deque<int> que;
// Push element x onto stack.
void push(int x) {
return que.push_back(x);
}
// Removes the element on top of the stack.
void pop() {
return que.pop_back();
}
// Get the top element.
int top() {
return que.back();
}
// Return whether the stack is empty.
bool empty() {
return que.empty();
}
};