汉诺塔问题看不懂,请大虾们指点,我是很菜

wangyan8576 wangyan8576 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
void move (char x,char y)
{
printf("%c-->%c\n",x,y);
}
viod hanoi(int n,char one,char two,char three));//这个递归函数搞不明白,整个就不知道怎么回事
{ if(n==1)move(one,three);
else
{
hanoi(n-1,one,three,two);//在这个语句先不段的调用自己,直到n=1为止?再向下进行?
move(one,three);
hanoi(n-1,two,one,three);
}
}
main()
{
int m;
printf("input the number of disks:");
scanf("%d,&m);
printf("the step to moving %3d disks:\n",m);
hanoi(m,'A','B','C');
}
...全文
评论 15
收藏 已收藏
分享
返回顶部
wangyan8576
新手乐园 33,315 成员 41,769 内容