225. Implement Stack using Queues
2016-07-04 16:21
246 查看
class Stack { public: // Push element x onto stack. void push(int x) { Q.push(x); } // Removes the element on top of the stack. void pop() { int len = Q.size(); for (int i = 1; i < len; i++){ Q.push(Q.front()); Q.pop(); } Q.pop(); } // Get the top element. int top() { int len = Q.size(); for (int i = 1; i < len; i++){ Q.push(Q.front()); Q.pop(); } int front = Q.front(); Q.push(front); Q.pop(); return front; } // Return whether the stack is empty. bool empty() { return Q.empty(); } private: queue<int> Q; };
相关文章推荐
- Android Stuido 使用过程中遇到的问题
- 父页面调用easyui datagrid
- 贝塞尔曲线(UIBezierPath)属性、方法汇总
- android安装内核module,提示Required key not
- iOS UIImage渲染模式 imageWithRenderingMode:
- 利用sass构建组件化的ui库
- UINavigationController的setViewControllers方法
- 成长记-UILable设置行间距
- easyui1.4.1下的tree
- Vue.js初探
- android bluedroid 协议栈里面的各个组件之间的消息处理机制
- Android 设计模式 笔记 - Builder模式
- solr msg=SolrCore 'collection1' is not available due to init failure
- arduino安装ESP8266 Arduino core
- Hive 或 Impala 的数据类型与 对应底层的 Parquet schema的数据类型不兼容
- Angular ui-router同时加载多个视图,根据不同url在同一个视图切换内容模板
- 1017. Queueing at Bank (25)
- discriminator-value
- Concurrent包学习之 BlockingQueue源码学习
- 2016.07.04,英语,《Vocabulary Builder》Unit 23