225 Implement Stack using Queues
2015-11-14 20:38
393 查看
class Stack { public: // Push element x onto stack. void push(int x) { q1.push(x); } // Removes the element on top of the stack. void pop() { while(q1.size()!=1) { q2.push(q1.front()); q1.pop(); } q1.pop(); q1 = q2; while(!q2.empty()) q2.pop(); } // Get the top element. int top() { return q1.back(); } // Return whether the stack is empty. bool empty() { return q1.empty(); } private: queue<int> q1; queue<int> q2; };
相关文章推荐
- 232 Implement Queue using Stacks
- 每天学一点easyui②
- RMQ(Range Minimum Query)问题(转)
- 隐藏uitabbar的代码
- UVa133 - The Dole Queue
- UISwitch(开关控件)、UISegmentedControl(分段控件)
- [leetcode] Range Sum Query 2D - Immutable
- 《iOS Human Interface Guidelines》——Icons and Graphics
- 10.UIImageView图片视图
- iOS开发——UI组件
- 设计模式系列二——Builder模式
- IOS 为UILabel和UIImageView添加长按复制功能
- 9.UITouch 保存手指的信息(触摸的点
- ui总结
- kendo ui的treeView节点点击事件修改和grid的配置的一点总结
- 九度OJ 1262:Sequence Construction puzzles(I)_构造全递增序列 (DP)
- 九度OJ 1262:Sequence Construction puzzles(I)_构造全递增序列 (DP)
- UI第四天 触摸 响应者链 target-action
- TI DSP TMS320C66x学习笔记之通用并行端口uPP(二)
- iOS UI CodeSnippet