汉诺塔问题
1 #include "stdio.h" 2 main()
3 {void hanoi(int,char,char,char);
4 int m;
5 printf("input the number of disks:");
6 scanf("%d",&m);
7 printf("The step to moving %d disks:\n",m);
8 hanoi(m,'A','B','C');
9 }
10 void hanoi(int n,char a,char b,char c)
11 {//void move(char,char);
12 if(n==1) move(a,c);
13 else
14 {hanoi(n-1,a,c,b);
15 move(a,c);------------------这一上的都能理解
16 hanoi(n-1,b,a,c); ——————————————————————这一步执行的话每一次递归又要执行第14.15步,该怎么理解
17 }
18 }
19 void move(char x,char y)
20 {printf("%c-->%c\n",x,y);
21 }