#include <iostream>
#include <stack>
using namespace std; template <typename T> class SQueue
{
public:
SQueue():cnt(){}; void push(const T& node);
T pop();
int getSize(); private:
stack<T> pushstack;
stack<T> popstack; int cnt;
}; template <typename T> void SQueue<T>::push(const T& node)
{
pushstack.push(node); cnt++;
} template <typename T> T SQueue<T>::pop()
{
if(popstack.empty())
{
while(!pushstack.empty())
{
T tmp = pushstack.top();
pushstack.pop();
popstack.push(tmp);
}
} if(popstack.empty())
{
throw new exception();
} T ret = popstack.top();
popstack.pop(); cnt--; return ret;
} template <typename T> int SQueue<T>::getSize()
{
return cnt;
} int main()
{
SQueue<int> Queue;
Queue.push();
Queue.push();
Queue.push(); cout<<"currnet size:"<<Queue.getSize()<<endl; cout<<Queue.pop()<<endl; cout<<"currnet size:"<<Queue.getSize()<<endl; cout<<Queue.pop()<<endl;
cout<<Queue.pop()<<endl;
}

最新文章

  1. MySQL sharding的几个参考地址
  2. 回到过去美好的时光&mdash;&mdash;源代码版本管理Always Use source code Control
  3. C#读txt文件并写入二维数组中(txt数据行,列未知)
  4. Josephu--Java链表实现
  5. C# 创建系统服务并定时执行【转载】
  6. Android横竖屏切换及其相应布局载入问题
  7. poj3270Cow Sorting(置换)
  8. Oracle字符函数(转换大小写,替换等)
  9. Arduino 各种模块篇 粉尘传感器 dust sensor 空气质量检测
  10. Bootstrap入门(十五)组件9:面板组件
  11. vue中多个input绑定enter按键事件
  12. Power BI行级别安全性(数据权限管理)
  13. Linux指令集
  14. XML 和 DTD
  15. Ubuntu端口开放
  16. Python知识点整理,基础5 - 文件操作
  17. Video Processing and Communications:(视频处理和通信)
  18. SSM 框架快速整合实例--学生查询
  19. putty adb
  20. centos7环境下ELK部署之elasticsearch

热门文章

  1. 查找数N二进制中1的个数(JS版 和 Java版)
  2. 2014--9=17 软工二班 MyEclipse blue==2
  3. 格林治时间,也就是返回从 UTC 1970 年 1 月 1 日午夜开始经过的毫秒数。
  4. Java多线程4:synchronized关键字
  5. linux命令-shopt
  6. 如何禁用 radio ,设置为只读,不能选定
  7. ubuntu下安装Ming的教程
  8. arcgis engine 开发之QI
  9. npm安装插件提示
  10. apache启动报错(98)Address already in use: make_sock: could not bind to...