[LeedCode OJ]#225 Implement Stack using Queues

来源:互联网 发布:电力网络摄像头 编辑:程序博客网 时间:2024/05/19 13:30

 【 声明:版权所有,转载请标明出处,请勿用于商业用途。  联系信箱:libin493073668@sina.com】

题目链接:https://leetcode.com/problems/implement-stack-using-queues/

题意:
使用队列来模拟栈

思路:
使用双向队列能够很完美的实现

class Stack{    deque<int> in;public:    // Push element x onto stack.    void push(int x)    {        in.push_back(x);    }    // Removes the element on top of the stack.    void pop()    {        in.pop_back();    }    // Get the top element.    int top()    {        return in.back();    }    // Return whether the stack is empty.    bool empty()    {        return in.empty();    }};



0 0
原创粉丝点击