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 ...
随机推荐
- Bestcoders
Senior's Fish Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- chrome浏览器提取网页视频
http://blog.csdn.net/pipisorry/article/details/37728839 在我们平时上网看视频听音乐时都会产生缓存,可是我们非常难通过一些软件把当中的视频和音乐文 ...
- 本地文件上传到linux
首先下载插件,输入下面命令: yum -y install lrzsz 然后输入rz选择上传文件: rz 如果rz命令不好使的话,就输入: rz -be
- Laravel 数据库实例教程 —— 使用DB门面操作数据库
Laravel支持多种数据库,包括MySQL.Postgres.SQLite和SQL Server,在Laravel中连接数据库和查询数据库都非常简单,我们可以使用多种方式与数据库进行交互,包括原生S ...
- Spring Framework简单介绍
Spring Framework 学习java编程不知不觉已经三年时间了,開始的时候,总是喜欢看着视频,然后按部就班的敲打着键盘,每当系统正常执行后.心里乐开了花.最開始的时候,所有的代 ...
- EasyUI datagrid border处理,加边框,去边框,都能够
以下是EasyUI 官网上处理datagrid border的demo: 主要是这句: $('#dg').datagrid('getPanel').removeClass('lines-both li ...
- POJ 3252 Round Numbers 数学题解
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- Hotel poj 3667
Language: Default Hotel Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18020 Acc ...
- 【Selenium + Python】之OSError: [WinError 6] 句柄无效。
问题描述:执行多个用例的时候,会抛出异常: Traceback (most recent call last): File "F:\Demo\pomGisStu\gis\test_case\ ...
- PHP-Manual的学习----【语言参考】----【类型】-----【float浮点型】
笔记:1.浮点型(也叫浮点数 float,双精度数 double 或实数 real)可以用以下任一语法定义: <?php$a = 1.234; $b = 1.2e3; $c = 7E-10;?& ...