怎么用循环方法解汉诺塔问题?
下面是用递归方法解的汉诺塔问题:
#include<stdio.h>
/*prottype declaraions*/
void hanoi(int n,char one,char two,char there);
void move(char x,char y);
void main()
{
int a;
printf("input the number of diskes:");
scanf("%d",&a);
printf("The steps to moveing %d diskes:\n",a);
hanoi(a,'A','B','C');
}
void hanoi(int n,char one,char two, char there)
{
if(n==1)
move(one,there);
else
{
hanoi(n-1,one,there,two);
move(one,there);
hanoi(n-1,two,one,there);
}
}
void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}
但是作业要用循环方法。。。这个实在是对初学者来说太难了。。。。达人来帮下忙啊!!!
[此贴子已经被作者于2007-10-20 13:15:40编辑过]