http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
#include <set>
using namespace std; void insertbottom(stack<int> &S, int top) {
if (S.empty()) S.push(top);
else {
int tmp = S.top();
S.pop();
insertbottom(S, top);
S.push(tmp);
}
} void reversestack(stack<int> &S) {
if (S.empty()) return;
int top = S.top();
S.pop();
reversestack(S);
insertbottom(S, top);
} int main() {
stack<int> S;
S.push();
S.push();
S.push();
S.push();
reversestack(S);
while (!S.empty()) {
cout << S.top() << endl;
S.pop();
}
return ;
}

最新文章

  1. [C#] 走进异步编程的世界 - 剖析异步方法(下)
  2. [Leetcode] Bulls and Cows
  3. css实现一行文字居中,多行文字居左
  4. Expert 诊断优化系列------------------你的CPU高么?
  5. 浅谈设计模式--组合模式(Composite Pattern)
  6. Ajax请求SpringMVC
  7. 【转】VS2012编译出来的程序,在XP上运行,出现“.exe 不是有效的 win32 应用程序” “not a valid win32 application”
  8. String类 and StringBuffer类
  9. Jquery 工具类函数
  10. PHP中Global和Local范围以及Static变量
  11. PHP 安装 Xdebug 扩展(一)
  12. ansible 批量安装zabbix agentd客户端
  13. Collections -- OrderedDict类
  14. (Solved) Nexiq USB link&#160;with CAT ET: connection error 149
  15. ElementTriArgyris
  16. C语言与数据库操作入门
  17. E 定向 牛客练习赛25
  18. 管理KVM虚拟机(二)
  19. IO知识点整理(四种基类的使用)
  20. 16 go操作Mysql

热门文章

  1. 【JQuery Easy UI】后台管理系统的简单布局分享
  2. SpringMVC 学习笔记(十一) SpirngMVC执行流程
  3. 清除掉AD的相关属性!
  4. 常用IIS mime类型
  5. Unix编程第7章 进程环境
  6. 【Axure插件】之浏览器打开失败
  7. Spring读书笔记-----Spring核心机制:依赖注入
  8. Sublime Text3 运行python(转)
  9. openresty 定时器
  10. 【转】利用Python中的mock库对Python代码进行模拟测试