#include<stdio.h>
typedef struct BiNode
{
int data;
struct BiNode *lchild,*rchild;
}BiTnode,*BiTree;
//先序遍历
void PreOder(BiTree T)
{
if(T!=NULL){
visit(T);
PreOder(T->lchild);
PreOder(T->rchild);
}
}
//求树的深度
int treeDepth(BiTree T)
{
if(T == 0)
return 0;
else
{
int l=treeDepth(T->lchild);
int r=treeDepth(T->rchild);
//左右子树深的加一
return l>r? l+1:r+1;
}
}
二叉树递归前序遍历和求深度
最新推荐文章于 2023-04-12 16:23:11 发布