当前位置: 代码迷 >> C语言 >> [讨论]难道没人会这个题吗,怎么没人回复?
  详细解决方案

[讨论]难道没人会这个题吗,怎么没人回复?

热度:148   发布时间:2007-08-22 23:34:34.0
[讨论]难道没人会这个题吗,怎么没人回复?
这个程序是解决一个河内塔的问题,并非真正的移动,这只是一个移动的方案!
请哪位仁兄帮我解决一下难道,我实在看不懂Hanoi()函数是怎么工作的,希望能把详细工作步骤写一下,谢谢:比如:第一步做什么,第二步做什么等等,
假设用户输入的是3!


#include <stdio.h>
void main()
{
int number;
printf("The Tower of Hanoi program.\n");
printf("Please enter the number of diske :");
scanf("%d",&number);
Hanoi('A','B','C',number);
}

int Hanoi(char one,char two,char three,int n) /*函数调用*/
{

if(n==1)
printf("%c-->%c.\n",one,three);
else
{
Hanoi(one,three,two,n-1);
printf("%c-->%c.\n",one,three);
Hanoi(two,one,three,n-1);
}
}
搜索更多相关的解决方案: 做什么  工作  include  number  color  

----------------解决方案--------------------------------------------------------
reursion --- you have to overcome this concept yourself.

try to understand the recursion for calculating n! first.

----------------解决方案--------------------------------------------------------
reursion --- you have to overcome this concept yourself.

try to understand the recursion for calculating n! first.
这是什么意思呀
----------------解决方案--------------------------------------------------------
意思是你自己先写出计算n的阶乘的递归函数并好好理解
----------------解决方案--------------------------------------------------------

int f(int n)
{
if(n==1)
return 1;
else
sum=f(n-1)*n;
return sum;
}


这个我很好理解呢!


----------------解决方案--------------------------------------------------------
int Hanoi(char one,char two,char three,int n) /*函数调用*/
{

if(n==1)
printf("%c-->%c.\n",one,three);
else
{
Hanoi(one,three,two,n-1);
printf("%c-->%c.\n",one,three);
Hanoi(two,one,three,n-1);
}
}

我是想知道它是怎么工作的?举个例子我就很好理解了,比如输入是3。
----------------解决方案--------------------------------------------------------

真要解释的话的确比较麻烦,楼主不妨在必要的代码上设断点,通过调试一步步看,就能看出名堂来,本人觉得满麻烦的。
----------------解决方案--------------------------------------------------------

好难啊 不会


----------------解决方案--------------------------------------------------------
我想说的是,你把程序运行出来就知道怎么做的了
递归有很多种,你在网上搜,你会学很多

[此贴子已经被作者于2007-8-23 8:39:11编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案