添加了模板类应用

 /*************************************************************************
> File Name: 05_StackMakeQueue.cpp
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: 2016年08月29日 星期一 19时32分12秒
************************************************************************/ #include <stdio.h>
#include <bits/stdc++.h> using namespace std; template<class T>
class qStack
{
private:
stack<T> stack1;
stack<T> stack2;
int size; public:
qStack()
{
size = ;
}
void push(T &node)
{
stack1.push(node);
size = stack1.size();
}
T pop()
{
assert(this->size > );
T ret = ;
if (this->size == )
{
ret = stack1.top();
stack1.pop();
this->size = ;
return ret;
}
if (this->size > )
{
while (stack1.size())
{
stack2.push(stack1.top());
stack1.pop();
}
ret = stack2.top();
stack2.pop(); while (stack2.size())
{
stack1.push(stack2.top());
stack2.pop();
}
this->size --;
return ret;
}
}
}; int main()
{
qStack<int> quque;
for (int i = ; i < ; i++)
{
cout << i << " push" << endl;
quque.push(i);
}
for (int i = ; i < ; i++)
{
cout << quque.pop() << " pop" << endl;
}
for (int i = ; i < ; i++)
{
cout << i << " push" << endl;
quque.push(i);
}
for (int i = ; i < ; i++)
{
cout << quque.pop() << " pop" << endl;
}
cout << endl;
}

最新文章

  1. SQL SERVER特殊行转列案列一则
  2. Android笔记:数据储存
  3. CF 115B Lawnmower(贪心)
  4. 调用jar程序,读取与jar同级的配置文件。
  5. nusoap
  6. WWDC 2016 总结
  7. c# web 缓存管理
  8. CentOS hadoop配置错误Incorrect configuration: namenode address dfs.namenode.servicerpc-address ...
  9. PDO应用
  10. JQuery datepicker 用法
  11. Java——(四)Collection之Set集合TreeSet类
  12. 【ICIP2013】MULTI-SOURCE IMAGE AUTO-ANNOTATION
  13. PPT排版细节,写给大家看的设计书,完美总结
  14. LVS集群TUN模式实例(5)
  15. 内核级线程(KLT)和用户级线程(ULT)
  16. A real example of vioplot in R (sample data and code attached)
  17. 集体干死java 在启动.sh
  18. 前端学习 -- Html&amp;Css -- 相对定位 绝对定位 固定定位
  19. linux rpm 安装后 mysql 默认安装目录等信息
  20. C# 各种输入格式验证#各种输入格式验证

热门文章

  1. poj 3134 Power Calculus(IDA*)
  2. MySQL主从复制的原理及配置
  3. MySQL 日期时间
  4. js关闭当前页面/关闭当前窗口
  5. js 创建List&lt;Map&gt; 这种格式的集合
  6. 【转】深入浅出异步I/O模型
  7. TCP/IP协议族-----13、运输层简单介绍
  8. [Angular 2] Create template with Params
  9. QT程序在windows下部署发布
  10. 项目源码--Android新闻财经类商用要求源码