Implement Queue using Stacks
2015-10-23 10:42
477 查看
class Queue { stack<int> input,output; public: // Push element x to the back of queue. void push(int x) { input.push(x); } // Removes the element from in front of queue. void pop(void) { peek(); output.pop(); } // Get the front element. int peek(void) { if(output.empty()) { while(!input.empty()) { output.push(input.top()); input.pop(); } } return output.top(); } // Return whether the queue is empty. bool empty(void) { if(input.empty()&&output.empty()) return true; } };
相关文章推荐
- hdu 5504 GT and sequence【BestCoder Round #60 】
- android GTS-- com.google.android.xts.placement.UiPlacementTest fail
- fogcloud api V2版本测试的x-Request sign配置生成
- ios读取通讯录并美化 文字生成头像UI
- 理解 Android Build 系统
- Android,UI主线程与子线程的关系
- Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to us
- android 中UID与PID的作用与区别
- No usable Android build tools found. Highest installed version is xx; minimum version required is 19
- [OrangePi] Building the system
- ./configure -build,-host,-target设置
- request获取前台表单
- [转载] 为 Key-Value 数据库实现 MVCC 事务
- BIOS设置之UEFI/Legacy BIOS切换图文详解
- UEFI+GPT引导实践篇(二):UEFI引导安装64位Win7/Win8
- UEFI+GPT引导实践篇(一):切换到UEFI启动,准备安装介质
- UEFI+GPT引导基础篇(一):什么是GPT,什么是UEFI?
- Flash Builder4.7 更新Air SDK及FlashPlayer
- Android Call requires API level 11 (current min is 8)的解决方案
- easyUI dialog弹出时适应页面大小