您的位置:首页 > 编程语言 > C语言/C++

汉诺塔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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: