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 ...
随机推荐
- Oracle LOB字段判空
dbms_lob.getlength() dbms_lob.getlength(null) 会报错--- Oracle 默认为clob字段插入empty_clob()
- jdk1.6 升级到 jdk1.7
将 jdk1.6 升级到 jdk1.7 下载jdk-7u11-linux-x64.tar.gz tar zxvf jdk-7u11-linux-x64.tar.gz mkdir /usr/l ...
- 再议urlconnection和socket区别
利用URL进行通信与利用socket进行通信有许多相似之处.它们都是利用建立连接.获取流来进行通信.那么,它们的区别在何处呢? 利用socket进行通信时,在服务器端运行一个socket通信程序 ...
- .Net Framework 与 SQL Server 2005 混乱的时间最大最小值
Net Framewrok 中,DateTime.MinValue => 0001/01/01 00:00:00SqlDateTime.MinValue.Value => 1753/01 ...
- JS 正则 钱
function ValidateIsDecial(sValue) { return (!sValue && !!!sValue && /^[0-9]{1,10}(\. ...
- Foundation框架 - NSDictionary类、NSMutableDictionary类
NSArray.NSSet.NSDictionary /* 集合 1.NSArray\NSMutableArray * 有序 * 高速创建(不可变):@[obj1, obj2, obj3] * 高速訪 ...
- Java中synchronized用在静态方法和非静态方法上面的区别
synchronized 修饰在 static方法和非static方法的区别 在Java中,synchronized是用来表示同步的,我们可以synchronized来修饰一个方法.也可以sync ...
- CONTROLLER_NAME 常量 当前访问的控制器
CONTROLLER_NAME 常量 当前访问的控制器
- ListView中加载大量的图片
情况是这样的:我需要把大约四五十个车标在一个listView中展示出来,一般在用ListView的时候撑死十来个图标,按不同分类使用,这倒好办,在创建view的时候使用R.drawable.xxx指定 ...
- linux用一键安装包 禅道
----------------1.重启apache 和 mysql /opt/zbox/zbox restart -----------------2.问题1:发现端口被占用 apache启动报错( ...