|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
废话不说,下面是代码:
- #include <stdio.h>
- int i=1;
- void move(char a,char b)
- {
- printf(" 第%d步:%c------->%c\n",i,a,b);
- }
- void haoni(int n,char one,char two,char three)
- {
- if(n==1)
- {
- move(one,three);
- i++;
- }
- else
- {
- haoni(n-1,one,three,two);
- move(one,three);i++;
- haoni(n-1,two,one,three);
- }
- }
- void main()
- {
- int f;
- char x = 'A',y = 'B',z = 'C';
- printf("Input f:");
- scanf("%d",&f);
- haoni(f,x,y,z);
- }
复制代码
有了这个程序以后,把汉诺塔打通关就只是时间和耐心的问题了。呵呵……
不过,我之所以能写出这个代码,完全是因为多看了几遍鱼哥的视频以后,代码基本上都背下来了……
真心说,我还是不明白代码中haoni()函数的运行规则……
希望哪位仁兄能给个我能看得明白的解释……谢谢了。。。
|
|