//大的必须在小的下面
#include
#include
int main ()
{
void hanoi(int n,char one,char two,char three);//定义 n为有几个盘,one为第一个盘,依次后推
int m; //盘的数量
printf("input the number of diskes:");
scanf("%d",&m);
printf("the step to moving %d disles:n",m);
hanoi(m,'A','B','C'); //调用汉罗塔交换的函数
return 0;
}
void hanoi(int n,char one,char two,char three)//定义 n为有几个盘,one为第一个盘,依次后推
{
void move(char x,char y); //声明有move这个函数,只是还没加载到,
若move函数在此函数前,则不必声明
if(n==1) move(one,three);
else //汉罗塔的交换思想 关键
{
hanoi(n-1,one,three,two); //将第一盘(n-1)个借助第三盘放置第二盘
(不能借助第一盘,,会变麻烦),此时第三盘为空, 第一盘剩下一个最大的
move(one,three); //调用move函数
hanoi(n-1,two,one,three); //与上面那个一样,只是交换顺序相反
}
}
void move(char x,char y)
{
printf("%c-->%cn",x,y); //打印出盘子交换的具体实现
}



