#include<stdio.h>
void move(char x,char y)
{
printf("%c->%c\n",x,y);
}
//将n个盘子从1中借助2移动到3
void hanoi(int n,char one,char two,char three)
{
if(n==1)
move(one,three);
else
{
hanoi(n-1,one,two,three);
move(one,three);
hanoi(n-1,two,one,three);
}
}
int main()
{
int m;//盘子个数
scanf("%d",&m);
hanoi(m,‘A‘,‘B‘,‘C‘);
return 0;
}汉诺塔-递归实现
时间:2018-03-30 13:02:20
收藏:0
阅读:181
原文:https://www.cnblogs.com/zhchoutai/p/8675535.html
评论(0)