6-4 二叉树求深度和叶子数 分数 10

人生乱弹 2年前 (2023) admin
11 0

int GetDepthOfBiTree(BiTree T)
{
if (!T)
return 0;
return GetDepthOfBiTree(T->lchild) > GetDepthOfBiTree(T->rchild) ? GetDepthOfBiTree(T->lchild) + 1 : GetDepthOfBiTree(T->rchild) + 1;
}
int LeafCount(BiTree T)
{
if (!T)
return 0;
if (!T->lchild && !T->rchild)
{
return 1 + LeafCount(T->lchild) + LeafCount(T->rchild);
}
return LeafCount(T->lchild) + LeafCount(T->rchild);
}

文章来源

版权声明:admin 发表于 2023年11月2日 am2:43。
转载请注明:6-4 二叉树求深度和叶子数 分数 10 | 银库

相关文章

本站主题由 OneNav 一为主题强力驱动