| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 981 人关注过本帖
标题:[求助]函数的递归调用
取消只看楼主 加入收藏
黑飞狐
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2005-11-12
收藏
 问题点数:0 回复次数:1 
[求助]函数的递归调用

#include "stdio.h"
void move(char x,char y)
{
printf ("%c-->%c\n",x,y);
}
void hanoi(int n,char one,char two,char three)
{
if(n==1)move(one,three);
else {
hanoi (n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}

main()
{
int m;
printf("input the number lr diskes:");
scanf("d",&m);
printf("the step to moving %3d diskes:\n",m);
hanoi(m,'A','B','C');
}
这是汉诺塔问题。请问有谁能解释一下hanoi函数的具体递归过程吗?我怎么总是看不明白。
void hanoi(int n,char one,char two,char three)
{
if(n==1)move(one,three);
else {
hanoi (n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
这中间到底是如何实现的呢?
即hanoi (n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);

搜索更多相关主题的帖子: 递归 函数 
2006-04-27 14:21
黑飞狐
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2005-11-12
收藏
得分:0 
我只是说为什么else {
hanoi (n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
第一个是one ,three,two,而后面的又是two,one,three呢?其作用是什么?

2006-04-27 22:29
快速回复:[求助]函数的递归调用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011825 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved