求助!!!汉诺塔递归怎么实现调用的,不明白
看了2天还是不明白,不是n==1是递归结束条件嘛,从4步后的调用怎么来的,带图。请详解,谢谢!!!
程序代码:#include<stdio.h>
#include<math.h>
int main()
{
int a;
void hanoi(int m,char one,char two,char three);
while(scanf("%d",&a)!=EOF)
{
int t=pow(2,a)-1;
printf("移动%d块盘子共有%d个步骤,如下\n",a,t);
hanoi(a,'A','B','C');
}
return 0;
}
void hanoi(int n,char one,char two,char three)
{
void move( int b,char x,char y);
if(n==1)
move(n,one,three);
else
{
hanoi(n-1,one,three,two);
move(n,one,three);
hanoi(n-1,two,one,three);
}
}
void move(int b,char x,char y)
{
printf("%d %c-->%c\n",b,x,y);
}[此贴子已经被作者于2017-3-7 16:58编辑过]









