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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. [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 ...

  4. 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 ...

  5. 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. ...

  6. 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  ...

  7. [Algorithom] Stack Data Structure in JavaScript

    A stack is a collection of items that obeys the principle of "last in, first out". Like a ...

  8. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  9. HDU 5929 Basic Data Structure 模拟

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

随机推荐

  1. SpringMVC传值(对象或字符串)给前台js

    java对象到js对象 1.先使用Jackson把对象转换成json串 ObjectMapper objectMapper = new ObjectMapper(); String json = ob ...

  2. Java注解基本介绍

    注解(Annotation),又称元数据(MetaData),提供了一种在代码中添加信息的形式化的方法,将元数据和源代码结合在一起. 1. 外部配置文件如XML存在的问题: 代码复杂度较高,需要编写很 ...

  3. chrome使用

    本文转载于http://www.cnblogs.com/tester-l/p/5743031.html Chrome调试工具各个工具的作用: Element Elements板块你可以看到整个页面的D ...

  4. 会话管理之session技术

    上一节我们总结了cookie技术,这节主要总结一下session技术. 1. session对象 在web开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占 ...

  5. ios 不通过import 调用其他控制器的方法

    ios 开发过程中在不通过import 调用其他类的方法 //获取类名 Class controller = NSClassFromString(@"controller"); / ...

  6. 摘录 LDAP

    1.LDAP就是 light DAP, 轻量级目录访问协议     LDAP是轻量目录访问协议(Lightweight Directory Access Protocol)的缩写     LDAP标准 ...

  7. nightwatch-js ----并发运行

    从v0.5开始nightwatch支持并发测试.通过在命令行中指定多个环境来工作,用逗号分隔.例如: $ nightwatch -e default,chrome 这样可以在多个相同或是不同的浏览器上 ...

  8. C----------输入一组整数,求出这组数字子序列和中的最大值,只要求出最大子序列的和,不必求出最大值对应的序列。

    © 版权声明:本文为博主原创文章,转载请注明出处 代码: #include <stdio.h> #include <stdlib.h> #define GET_ARRAY_LE ...

  9. JAVA问题之泛型数组

      java中类似下面的代码编译器是会报错的: LinkedList<LinkedList<String>>[] li=new LinkedList<LinkedList ...

  10. map端join

    package my.hadoop.hdfs.mapreduceJoin; import java.io.BufferedReader; import java.io.FileInputStream; ...