汉诺塔问题具体是怎么递归的??
#include<stdio.h>voidmove(chargetone,charputone){printf("%c-->%c\n",getone,putone);}v...
#include<stdio.h>
void move(char getone,char putone)
{
printf("%c-->%c\n",getone,putone);
}
void hanoit (int n,char a,char b,char c)
{
if(n==1) move(a,c);
else
{
hanoit(n-1,a,c,b);
move(a,c);
hanoit(n-1,b,a,c);
}
}
void main()
{
int m;
printf("Input the data:\n");
scanf("%d",&m);
printf("The step to moving %3d diskes:\n",m);
hanoit(m,'A','B','C');
} 展开
void move(char getone,char putone)
{
printf("%c-->%c\n",getone,putone);
}
void hanoit (int n,char a,char b,char c)
{
if(n==1) move(a,c);
else
{
hanoit(n-1,a,c,b);
move(a,c);
hanoit(n-1,b,a,c);
}
}
void main()
{
int m;
printf("Input the data:\n");
scanf("%d",&m);
printf("The step to moving %3d diskes:\n",m);
hanoit(m,'A','B','C');
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询