首页 > 其他 > 详细

汉诺塔问题

时间:2019-01-08 18:34:51      阅读:94      评论:0      收藏:0      [点我收藏+]

#include<stdio.h>
int main()
{
void hanoi(int n,char one,char two,char three);
int m;
printf("Inout the numbers of disks:");
scanf("%d",&m);
printf("The step to move %d disks:\n",m);
hanoi(m,‘A‘,‘B‘,‘C‘);
return 0;
}
void hanoi(int n,char one,char two,char three)
{
void move(char x,char y);
if(n==1)
move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}

void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}

汉诺塔问题

原文:https://www.cnblogs.com/hjn123hjn/p/10240452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!