问题是这样的:有三根针ABC,A针上有n个盘子,大小不等,大的在下小的在上.要求把这n个盘子从A针移到C针,可以借助B针,每次只能移动1个盘子,且在移动过程中3根针上都要保证大盘在下小盘在上.
具体的调用函数是:
void move (getone,putone)
char getone ,putone;
{printf("%c----%c\n",getone,put);
}
void hanoi (n,one,two,three)
char one,two,three;
int n;
{
if(n==1)move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
主函数没什么实际用途就是把步骤输出,我就不打了
我是个初学者,刚刚看到递归调用这里,有些不懂
陪伴而非守候
白衣染霜花
FFIVE
森栏
随时随地看视频慕课网APP