递归算法

来源:互联网 发布:局网络管理办法 编辑:程序博客网 时间:2024/05/16 06:47

递归算法

The Three Laws of Recursion
A recursive algorithm must have a base case.
A recursive algorithm must change its state and move toward the base case.
A recursive algorithm must call itself, recursively.


对应三条规则
1 写出初始情况返回值
2 写出操作,= +/- 等等
3 调用自己,并且传递参数,通过不停调用自己,最后能达到初始情况

递归算法不关心具体的实现,只关心具体某一步的实现

0 0
原创粉丝点击