#include <stdio.h>
int main()
{
void hanoi(int n, char one, char two, char three); //声明hanoi函数
int m;
printf("input the number of diskes:\n");
scanf("%d", &m); //收入要移动盘的数目
printf("The step of move %d diskes\n", m);
hanoi(m, 'A', 'B', 'C'); //赋值给hanoi函数
system("pause");
}
void hanoi(int n, char one, char two ,char three) //定义hanoi函数
{
void move(char x, char y); //声明move函数
if (n == 1) //递归函数的最后值
move(one, three); //赋值给move函数
else
//开始递归
{
hanoi(n - 1, one, three, two); //赋值给hanoi函数
move(one, three); //赋值给move函数
hanoi(n - 1, two, one, three); //赋值给hanoi函数
//这个函数的意思可以看做是:从上往下一共m个盘,
//将m-1个盘全部挪到two上,然后把m盘挪到three上,
//然后再将two上的所有盘挪到three上,就实现了。
//要挪m-1个盘在two上,必须把m-2个盘挪到three上,依次类推,层层递归。
}
//递归结束
}
void move(char x, char y) //定义move函数
{
printf("%c-->%c\n", x, y); //输出每一步的指向
}