递归和迭代的区别之我见

来源:互联网 发布:python加注释快捷键 编辑:程序博客网 时间:2024/04/26 06:36

递归:当一个函数包含着对它自身调用时就称这个函数式递归的

如典型的阶乘函数

int func(int n){//error detectif (n==1){return 1;}return func(n-1)*n;}

迭代就是不断的使用计算出来的结果来代替旧值
int func(int n){//error detectint result = 1;for (int i = 1;i <= n;i++){result *= i;}return result;}


一起学习,一起进步,欢迎访问我的博客:http://blog.csdn.net/wanghao109

原创粉丝点击