求汉诺塔算法实现过程中参数是如何变化的及详解。
#include<stdio.h>void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}
//将n个盘从one座借助two座,移到three座
void hanoi(int n,char one,char two,char three)
{
if(n==1)
move(one,three);//
else
{
hanoi(n-1,one,three,two); //
move(one,three);//
hanoi(n-1,two,one,three);//
}
}
int main()
{
int n;
printf("input the number of diskes:\n");
scanf("%d",&n);
printf("The step to moving %3d diskes:\n",n);
hanoi(n,'A','B','C');
return 0;
}