Data Structure Stack: Reverse a stack using recursion
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 ;
}
Data Structure Stack: Reverse a stack using recursion的更多相关文章
- UVa 11995:I Can Guess the Data Structure!(数据结构练习)
I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...
- UVA 11995 I Can Guess the Data Structure!(ADT)
I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...
- [UVA] 11995 - I Can Guess the Data Structure! [STL应用]
11995 - I Can Guess the Data Structure! Time limit: 1.000 seconds Problem I I Can Guess the Data Str ...
- uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)
11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operation ...
- UVA - 11995 - I Can Guess the Data Structure! STL 模拟
There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...
- Kattis -I Can Guess the Data Structure!
I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x1 ...
- [Algorithom] Stack Data Structure in JavaScript
A stack is a collection of items that obeys the principle of "last in, first out". Like a ...
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU 5929 Basic Data Structure 模拟
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
随机推荐
- [JAVA · 0基础]:11.终结者-final
关于finalkeyword的总结,是非常easy学习和掌握的,大致分为用final修饰的符号常量.类.方法.属性四部分.而这四部分的内容也是我们必须掌握的,非常有用.在项目中常常来利用finalke ...
- 企业级分布式存储应用与实战MogileFS、FastDFS
项目实战9—企业级分布式存储应用与实战MogileFS.FastDFS 目录 实战一:企业级分布式存储应用与实战 mogilefs 实现 原理 1.环境准备 2.下载安装,每个机器都一样 3.数据 ...
- git revert 后悔了 还原修改前的版本 + git 常用命令
昨天手残 然后在GitHub for windows 上点了revert 然后就给重置了 更手残的是又给同步了 . 但是 GitHub 会保留之前的版本 . 只要删掉本次修改就可. 解决方案: g ...
- X264学习1:简介
H.264是视频编码标准. X264是它的开源实现,是视频编码器. 目录 [隐藏] 1 编码器特性 2 输入输出文件类型 2.1 输入 2.2 输出 3 preset和tune系统 3.1 --pr ...
- 走进Struts2(五)— 值栈和OGNL
值栈 1.值栈是什么? 简单说:就是相应每个请求对象的轻量级的内存数据中心. Struts2引入值栈最大的优点就是:在大多数情况下,用户根本无须关心值栈,无论它在哪里,不用管它里面有什么,仅仅须要去获 ...
- 【Atheros】网卡驱动速率调整算法概述
我做网卡驱动,最主要的内容就是设计和改进速率调整算法,随着802.11协议簇的新标准越来越多,速率越来越高,调制编码方式也越来越多,一般来说,速率越高越可能丢包,速率越低越稳定,这是整体状况,但不是必 ...
- 【POJ-2524】Ubiquitous Religions(并查集)
并查集. #include<cstdio> #include<cstring> using namespace std; const int maxn = 55555; int ...
- mysqldump命令使用详解
mysqldump是一个数据库备份程序 用法:mysqldump [options] [db_name [tbl_name ...]] 描述:mysqldump是一个客户端逻辑备份的工作,备份的SQL ...
- random随机模块,time时间模块
random /随机模块: 作用: 在某个范围内取到每一个值得概率是相通的. 一.随机小数 random.random() import random print(random.random()) ...
- [08山东省选]2298 石子合并 即POJ 1738 An old Stone Game
2298 石子合并 2008年省队选拔赛山东 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 在 ...