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. myBatis插入oracle获取主键

    <insert id="insert" parameterType="com.inspur.biz.entry.SpLackApply"> < ...

  2. Loadrunner中对中文进行UTF-8转码的探索

    上一篇 / 下一篇  2010-02-22 15:20:28 查看( 2378 ) / 评论( 2 ) / 评分( 5 / 0 ) 这是一个HTTP接口测试中经常会碰到的问题,目前的服务器采用的都是U ...

  3. Android开发过程中遇到的问题集合(—)

    1. Re-installation failed due to different application signatures. 将原来的软件包删除掉,然后又一次安装一次就好了.在命令行上执行:a ...

  4. 受防火墙影响,win7的IPV6经常Ping不通,需要手动放行

    在路由器上面设置了IPV6隧道,路由自动给每台机器分配了IPV6地址. 然后总是发现过会IPV6就ping不通了,IPV6的网站也打不开. 经从次实验发现:关闭防火墙后立马就通了,打开防火墙后,过会又 ...

  5. str_replace 替换 小技巧

    // $id:1 $id:1,2,3,4,5 public function delete($id) { // 把1替换掉不允许删除ID为1的角色             在前面分别加了 , 号   ...

  6. 修改mysql数据库存储目录

    使用了VPS一段时间之后发现磁盘空间快满了.本人的VPS在购买的时候买了500gb的磁盘,提供商赠送了20GB的高性能系统磁盘.这样系统就有两个磁盘空间了.在初次安装mysql 的时候将数据库目录安装 ...

  7. vue2+element组件库开发

    Vue2:https://cn.vuejs.org/v2/guide/single-file-components.html element组件库:http://element-cn.eleme.io ...

  8. PHP自动加载功能原理解析

    前言 这篇文章是对PHP自动加载功能的一个总结,内容涉及PHP的自动加载功能.PHP的命名空间.PHP的PSR0与PSR4标准等内容. 一.PHP自动加载功能 PHP自动加载功能的由来 在PHP开发过 ...

  9. python 正則表達式推断邮箱格式是否正确

    import re def validateEmail(email):     if len(email) > 7:         if re.match("^.+\\@(\\[?) ...

  10. windows10系统自带输入法不能切换中文如何解决

    具体如下: 1.打开计算机管理软件,右击“开始”按钮,在弹出的菜单中选择“计算机管理”: 2.或在桌面右击“此电脑”图标,在弹出的菜单中选择“管理”: 3.在打开的计算机管理软件中,选择“系统工具”- ...