#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef struct BiTNode{
int data;
struct BiTNode *Lchild,*rchild;
}BiTNode,*BiTree;
// 求树的深度。
int maxDepth(BiTNode *root){
if(root==NULL)
return 0;
return fmax(maxDepth(root->rchild),maxDepth(root->Lchild))+1;
}
// 求阶乘
int fact(int n){
int temp=n==1?1:fact(n-1)*n;
return temp;
/* if(n==1)
return 1;
return fact(n-1)*n;*/
}
//求1+2+3+...+100
int add(int n){
if(n==1)
return 1;
return add(n-1)+n;
}
// 斐波那契数列
int fab(int n)
【算法】递归的十个例子(带输出 完整程序) 递归求树的深度,求阶乘,求1+2+3+...+100,斐波那契数列,最小公约数,汉诺塔问题,递归实现strlen,输出单链表,求单链表的长度
递归算法实践:十个经典示例解析
最新推荐文章于 2021-02-08 14:24:24 发布
本文详细介绍了递归在算法中的应用,包括计算树深度、阶乘、等差数列求和、斐波那契序列、求最小公倍数、解决汉诺塔问题、递归实现字符串长度、遍历单链表及计算链表长度等十个实例,通过完整程序展示递归的使用方法。

最低0.47元/天 解锁文章
805

被折叠的 条评论
为什么被折叠?



