Board logo

标题: C语言经典算法之汉诺塔2 [打印本页]

作者: 苹果也疯狂    时间: 2014-5-9 17:14     标题: C语言经典算法之汉诺塔2

move(char getone,char putone)
{
printf("%c-->%c\n",getone,putone);
}
void hanoi(int n,char one,char two,charthree)
{
if(n==1)move(one,three);
else{
hanio(n-1,one,three,two);   \*A针的n-1个盘子通过C针移到B*\
move(one,three);            \*A针的第n个盘子移到C针,打印出来*\
hanoi(n-1,two,one,three);   \*B针的n-1个盘子通过A针移到C*\
}
}
main()
{
int m;
printf("input the number of diskes:");
scanf("%d",&m);
printf("the step to moving %3d diskes:\n",m);
hanoi(m,'A','B','C');
}




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0