admin管理员组

文章数量:1636900

原题链接:https://leetcode/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();
    }
};

本文标签: LeetCodeImplementStackqueues