首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

帮忙分析下hanoi程序,该如何处理

2012-04-06 
帮忙分析下hanoi程序C/C++ code#include stdio.hint main(){ void hanoi(int n ,char one, char two, ch

帮忙分析下hanoi程序

C/C++ code
#include <stdio.h>int main(){ void hanoi(int n ,char one, char two, char three); int m; printf("Input the number of diskes:"); scanf("%d",&m); printf("The step to moving %d diskes:\n",m); 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 move(char x, char y){ printf("%c-->%c\n",x,y);}这代码中  hanoi(n-1, one, three, two);  move(one, three);  hanoi(n-1, two, one, three);是什么意思. 为什么下面还有个hanoi(n-1, two, one, three);


[解决办法]
帮你弄个详细分析的
|h(2,1,3,2)|h(1,1,2,3)=>move(1,3) <-----1------ 
| | move(1,2) <-----2------ 
| |h(1,3,1,2)=>move(3,2) <-----3------ 
|move(1,3) <-----4------ 

h(3,1,2,3) | |h(1,2,3,1)=>move(2,1) <-----5------ 
|h(2,2,1,3)|move(2,3) <-----6------- 
| |h(1,1,2,3)=>move(1,3) <-----7------ 


热点排行