http://community.csdn.net/Expert/topic/5312/5312945.xml?temp=.5996363递归
来源:互联网 发布:沙迪克火花机镜面编程 编辑:程序博客网 时间:2024/04/20 08:01
public class RecTest {
static int[] values = new int[3];
static void printArray(int i) {
if (i == 0) return;//当i=0的时候返回,因为此时数组的下标为-1,所以没有输出
else printArray(i - 1);
System.out.println("[" + (i - 1) + "] = " + values[i - 1]);
//当i不等于0的时候i-1,直到i=0,从i等于0,1,2,3开始算,输出数组的值
}
public static void main(String args[]) {
for (int i = 0; i < 3; i++) values[i] = i;
printArray(3);
}
}
public class RecTest {
static int[] values = new int[3];
static void printArray(int i) {
if (i == 0) return;
else printArray(i - 1);
System.out.println("[" + (i - 1) + "] = " + values[i - 1]);
}
public static void main(String args[]) {
for (int i = 0; i < 3; i++) values[i] = i;
printArray(3);
}
}
[0] = 0
[1] = 1
[2] = 2
本人数据结构学的不是太好,求哪为给讲解一下上面递归代码是怎么实现下面的输出结果的,请说明的详细些,谢谢
遇到递归记住2点就行了
1)递归程序有2个出口 一个是退出递归的条件 另一个是继续递归
2)递归调用后会返回调用他的函数
写递归的时候找到退出条件就好写了
看递归的时候画画图 记住返回就行了
自己写写 N! x的y次方 逆序输出字符串 慢慢就能理解了
(x的y次方可以用系统函数 逆序输出字符串可以用循环)
- http://community.csdn.net/Expert/topic/5312/5312945.xml?temp=.5996363递归
- http://community.csdn.net/Expert/topic/5159/5159271.xml?temp=.5758325
- http://community.csdn.net/Expert/topic/5289/5289483.xml?temp=.5684778#top
- RSS技术 http://community.csdn.net/Expert/topic/5671/5671490.xml?temp=.2223627
- Track Javascript( http://community.csdn.net/Expert/topic/5329/5329152.xml?temp=.82008)
- http://community.csdn.net/Expert/topic/5758/5758279.xml?temp=.4552118
- http://search.csdn.net/Expert/topic/2489/2489689.xml?temp=1.829165E-02
- 一些不错的资源(收藏,出处:http://search.csdn.net/Expert/topic/2480/2480003.xml?temp=.2231562)
- 关于vc的mshflexgrid控件的用法(转载:原地址:http://search.csdn.net/Expert/topic/1830/1830926.xml?temp=.8678705)
- 关于Dcom数据库的三层原理片断(原地址:http://search.csdn.net/Expert/topic/567/567846.xml?temp=.0147211)
- http://community.csdn.net/Expert/TopicView3.asp?id=5095340
- 百度搜索中关键字的编码方法和解码方法http://community.csdn.net/Expert/TopicView3.asp?id=5744800
- 引用新浪天气预报http://community.csdn.net/
- 解析xml http://topic.csdn.net/u/20070409/19/6BAD2D5B-D78B-4CA1-81C7-F687D7E9FDE0.html
- http://topic.csdn.net/t/20030106/17/1332084.html
- http://topic.csdn.net/t/20050406/11/3912976.html
- http://topic.csdn.net/t/20031204/21/2528768.html
- http://topic.csdn.net/t/20061023/19/5103384.html
- Installed software
- 一个有经验借鉴的小店铺经营之道
- 一起来抗议“注册用户才能发表评论”
- vs 2005调试
- 信息周刊:拨开SOA迷雾
- http://community.csdn.net/Expert/topic/5312/5312945.xml?temp=.5996363递归
- 工作已经2周多
- 系统安全基础知识之Nbtstat命令详解
- 个人简历
- 直升机飞行机理
- 系统安全之堵住日常操作易泄密的漏洞
- J2SE发展演变史
- 利用 IIS日志追查网站入侵者
- [原创](Object/(DataSet,DataReader) Relational Mapping)ODRM