汉诺塔C++版的递归实现。。。。
2011-05-01 16:46
387 查看
/*************************************************************** * * * 作者:祝靖俊 * * 描述:汉诺塔的递归实现 * * 实现语言:C++ * * 运行环境:标准C++运行环境 * * * ***************************************************************/ #include <iostream> using namespace std; void hannoi(int count, char* target, char* from, char* temp); void move(int count, char* target, char* from); int main(){ hannoi(3, "target", "from", "temp"); return 0; } void hannoi(int count, char* target, char* from, char* temp){ if(count==1){ move(count, target, from); }else{ hannoi(count-1, temp, from, target); move(count, target, from); hannoi(count-1, target, temp, from); } } void move(int count, char* target, char* from){ cout << "把" << count << "从" << from << "移动到" << target << endl; }
本文出自 “阿祝的笔记” 博客,请务必保留此出处http://cymbidsoft.blog.51cto.com/1671306/557325
相关文章推荐
- 汉诺塔问题C++的递归实现 [
- 3行核心代码解决汉诺塔问题(C++递归实现)
- 汉诺塔与递归之C++ 和Python实现
- C++_递归实现汉诺塔
- C++ 递归实现汉诺塔
- 汉诺塔非递归实现,并用图像演示
- 递归下降方法和LL(1)实现计算器C++
- 汉诺塔问题--递归实现
- 递归实现二叉查找树 C++
- C++实现黄金分割数列(斐波纳奇数列)(非递归)
- c++实现二叉树的先序遍历,中序遍历,后序遍历(递归方法)及运行实例结果
- 汉诺塔的递归实现
- 初学者看过来:简单谈谈 C/C++ 递归的思想,实现,以及和循环的关系。
- 汉诺塔(递归实现)
- c++递归实现reverse
- 汉诺塔递归实现[C代码]
- 20170219C++项目班02_02递归下降算法/解析器/Scanner实现
- C++递归实现strlen函数功能
- c++实现二叉树的非递归创建以及非递归先序、中序、后序遍历
- 对半搜索递归实现 C++