汉诺塔中的问题。。。请教各位啊
时间:2011-12-09
来源:互联网
#include<iostream>
using namespace std;
int main()
{
void hanoi(int n,char one,char two,char three);
int m;
cout<<"input the number of disks:";
cin>>m;
cout<<"the steps of moving "<<m<<"disks:"<<endl;
hanoi(m,'A','B','C');
return 0;
}
void hanoi(int n,char one,char two,char three)
{
void move(char x,char y);
if(n==1) move(one ,three);
else
{
hanoi(n-1,one,three,two);// 这包括以下的三行。哪位大侠能够解释一下这的递归啊。不明白啊。
move(one,three);
hanoi(n-1,two,one,three);
}
}
void ;lmove(char x,char y)
{
cout<<x<<"-->"<<y<<endl;
}
using namespace std;
int main()
{
void hanoi(int n,char one,char two,char three);
int m;
cout<<"input the number of disks:";
cin>>m;
cout<<"the steps of moving "<<m<<"disks:"<<endl;
hanoi(m,'A','B','C');
return 0;
}
void hanoi(int n,char one,char two,char three)
{
void move(char x,char y);
if(n==1) move(one ,three);
else
{
hanoi(n-1,one,three,two);// 这包括以下的三行。哪位大侠能够解释一下这的递归啊。不明白啊。
move(one,three);
hanoi(n-1,two,one,three);
}
}
void ;lmove(char x,char y)
{
cout<<x<<"-->"<<y<<endl;
}
作者: zhangtieqiang 发布时间: 2011-12-09
这个你随便找一下就能理解啊
就是把要移动那块的上面所有部分从 A移动到B 然后把要移动的那块从A移动到C 最后吧原先的移动到B的部分从B移动到A
就是把要移动那块的上面所有部分从 A移动到B 然后把要移动的那块从A移动到C 最后吧原先的移动到B的部分从B移动到A
作者: hnuqinhuan 发布时间: 2011-12-09
不太明白。。那三行是先执行第一行直到不能执行之后执行后面的,还是执行完第一行在执行后面的再递归啊。谁能完整的讲讲啊 。。。。
作者: zhangtieqiang 发布时间: 2011-12-09
单步调试跟踪一下,多看几遍你就懂了
作者: jackhanzy 发布时间: 2011-12-09
我是在那个hanoi函数里面的递归的那三行不明白怎么执行的。能详细的讲讲么?
作者: zhangtieqiang 发布时间: 2011-12-09
设一小点,点步跟踪一遍,是学习递归的不二法门。
作者: neolyao 发布时间: 2011-12-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28