LeetCode_Implement Stack using Queues

来源:互联网 发布:win10用的c语言编译器 编辑:程序博客网 时间:2024/04/29 06:02

原题链接: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();    }};
0 0
原创粉丝点击