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. AOP切面编程在android上的应用

    代码地址如下:http://www.demodashi.com/demo/12563.html 前言 切面编程一直是一个热点的话题,这篇文章讲讲一个第三方aop库在android上的应用.第三方AOP ...

  2. Tomcat Https配置

    一.生成KeyStore 打开命令行,输入:keytool -genkey -alias tomcat_server -keyalg RSA -storepass jimmypwd -validity ...

  3. group by having和connect by

    --使用group by 子句对数据进行分组:对group by 子句形成的组运行聚集函数计算每一组的值:最后用having 子句去掉不符合条件的组.--having 子句中的每一个元素也必须出现在s ...

  4. Linux下安装jdk8的方法

    一.yum安装 只需要一条命令就可以安装jdk: yum install java--openjdk* -y 执行过这条命令无需配置,直接可以使用. 二.下载tar包安装 下载jdk8 登录网址:ht ...

  5. OpenOffice/LibreOffice的行距问题

    OpenOffice和LibreOffice的默认行距(行间距)都很宽,可以通过以下方法设置. 格式 -> 页面 -> 文字网格 -> 不使用网格

  6. hive中遇到的问题

    ) from t_1 where country ='China' group by (name = 'qq'); 结果图 select * from t_sz_part; 按照理解来说,应该只有一个 ...

  7. Google Code Jam 2014 Round 1 A:Problem B. Full Binary Tree

    Problem A tree is a connected graph with no cycles. A rooted tree is a tree in which one special ver ...

  8. spring boot配置文件

    1.spring boot通常打成一个jar文件发布,想修改配置文件比较麻烦,但他提供了一种读取外部配置文件的方式.在代码的主类中增加如下代码 System.setProperty("spr ...

  9. JS 创建对象(常见的几种方法)

    贴个代码先: function O(user,pwd){ //use constructor this.user=user; this.pwd=pwd; this.get=get; return th ...

  10. 深入解读DevOps 开发-运维

    历史回顾 为了能够更好的理解什么是DevOps,我们很有必要对当时还只有程序员(此前还没有派生出开发者,前台工程师,后台工程师之类)这个称号存在的历史进行一下回顾. 如编程之道中所言: 老一辈的程序员 ...