您的位置:首页 > 产品设计 > UI/UE

LeetCode_Implement Stack using Queues

2015-09-11 14:17 441 查看
原题链接:https://leetcode.com/problems/implement-stack-using-queues/

思路:使用双端队deque列实现栈
class Stack {
public:
deque<int> que;
// Push element x onto stack.
void push(int x) {
que.push_front(x);
}

// Removes the element on top of the stack.
void pop() {
que.pop_front();
}

// Get the top element.
int top() {
if(!que.empty())
{
int x = que.front();
return x;
}
}

// Return whether the stack is empty.
bool empty() {
return que.empty();
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: