程序如下:
void move(char x,char y){
printf("%c-->%c\n",x,y);
}
void hanoi(int n,char one,char two,char three){
/*将n个盘从one座借助two座,移到three座*/
if(n==1) move(one,three);
else{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
main(){
int n;
printf("input the number of diskes:");
scanf("%d",&n);
printf("The step to moving %3d diskes:\n",n);
hanoi(n,'A','B','C');
}
当n=3的时候,请高手帮我详细写出程序递归执行的过程。该程序中没有计算的表达式,就 hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
靠个参数传递,怎么传递啊?我还是不明白啊,高手帮帮我,我一定要弄明白位置,我太笨了。
谭先生的C教程电子版哪有下载啊?