用两个队列实现栈
来源:互联网 发布:医院感染管理三级网络 编辑:程序博客网 时间:2024/06/01 17:25
#include <queue>template <typename T>class CStack{public:void AddToTail(const T&);T deleteHead();private:std::queue<T> queue1;std::queue<T> queue2;};template <typename T>void CStack<T>::AddToTail(const T& value){queue1.push(value);}template <typename T>T CStack<T>::deleteHead(){int flat = 0;if (!queue1.empty()){while (queue1.size() > 1){T& data = queue1.back();queue2.push(data);queue1.pop();}flat = 1;}else{while (queue2.size() > 1){T& data = queue2.back();queue1.push(data);queue2.pop();}flat = 2;}T result;if (flat == 1){result = queue1.back();queue1.pop();}else if (flat == 2){result = queue2.back();queue2.pop();}else{throw new exception("stack is empty");}return result;}
0 0
- 用两个栈实现队列 & 用两个队列实现栈
- 用两个队列实现栈&用两个栈实现队列
- 用两个栈实现队列 & 两个队列实现一个栈
- 两个栈实现队列&&用两个队列实现一个栈
- 用两个栈实现队列 & 两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- ProgressBar-进度条案例
- Android中的文本框,图片以及点击事件的设置
- 学习SpringMVC(十)之确定目标方法POJO类型参数
- canvas学习线条属性之lineJoin、miterLimit
- 计蒜客之A+B+C问题
- 用两个队列实现栈
- Java中异常机制的意义
- commons-httpclient 3.x如何按照host单独配置连接数和超时参数
- HDUOJ Max Sum Plus Plus Plus--1244
- 字符串转换md5
- C++学习笔记(四)C++ 概述
- 300. Longest Increasing Subsequence最长递增子序列
- sdut 3251 Nias and Tug-of-War 模拟
- 回溯法,DFS的应用