LeetCode "Implement Stack using Queues"
2015-06-16 04:35
561 查看
Two-queue solution
class Stack { queue<int> q; queue<int> q0; int _top; public: // Push element x onto stack. void push(int x) { q.push(x); _top = x; } // Removes the element on top of the stack. void pop() { auto len0 = q.size(); while(--len0) { q0.push(q.front()); q.pop(); } q.pop(); while(!q0.empty()) { q.push(_top = q0.front()); q0.pop(); } } // Get the top element. int top() { return _top; } // Return whether the stack is empty. bool empty() { return q.empty(); } };
相关文章推荐
- Global build settings
- Global build settings
- UIProgressView
- mysql升级报错:ERROR 2013 (HY000): Lost connection to MySQL server during query
- MINIGUI 中主窗口、控件(即子窗口)的理解
- Android 使用XML做动画UI的深入解析
- 创优翼推荐:交互设计的7大定律。
- ActiveMQ的queue以及topic两种消息处理机制分析
- 如何取web.xml中 定义的 context-param 对应的value值?
- Handler,Looper,MessageQueue的工作原理
- iOS 基本UI控件
- Arduino 入门程序示例之直流电机(2015-06-15)
- easyui datagrid 通过复选框删除新追加的数据问题
- UIImageView
- WebRequest 对象的使用
- iOS8 UITableViewCell设置 setSeparatorInset:UIEdgeInsetsZero不起作用的解决办法
- 现代福尔摩斯 - Oxygen Forensic Suite
- Swing-setOpaque()用法-入门
- [编程题]Be Unique (赌徒下注问题)
- 苹果开发 笔记(38)UIImagePickerController