标签:obj div style The vat mys ali you queue
class MyStack { public: /** Initialize your data structure here. */ MyStack() { } /** Push element x onto stack. */ void push(int x) { std::queue<int> aux; aux.push(x); while(!_data.empty()) { aux.push(_data.front()); _data.pop(); } swap(aux,_data); } /** Removes the element on top of the stack and returns that element. */ int pop() { int x = _data.front(); _data.pop(); return x; } /** Get the top element. */ int top() { return _data.front(); } /** Returns whether the stack is empty. */ bool empty() { return _data.empty(); } private: std::queue<int> _data; }; /** * Your MyStack object will be instantiated and called as such: * MyStack obj = new MyStack(); * obj.push(x); * int param_2 = obj.pop(); * int param_3 = obj.top(); * bool param_4 = obj.empty(); */
Leetcode 225. Implement Stack using Queues
标签:obj div style The vat mys ali you queue
原文地址:https://www.cnblogs.com/randyniu/p/9309440.html