void hanoi(int n,char one,char two,char three)
{
if(n==1)
move(n,one,three); //将第n个盘从第1个柱子移到第3个柱子
else
{
hanoi(n-1,one,three,two); //将上面的n-1个盘从第1个柱子通过第3个柱子移动到第2个柱子
move(n,one,three);
hanoi(n-1,two,one,three);
}
}
void move(int n,char x,char y)
{
printf("%d %c %c\n",n,x,y);
}
{
if(n==1)
move(n,one,three); //将第n个盘从第1个柱子移到第3个柱子
else
{
hanoi(n-1,one,three,two); //将上面的n-1个盘从第1个柱子通过第3个柱子移动到第2个柱子
move(n,one,three);
hanoi(n-1,two,one,three);
}
}
void move(int n,char x,char y)
{
printf("%d %c %c\n",n,x,y);
}