第一题:
int LeafCount(BiTree T) {
if (T == NULL) {
return 0;
}
if (T->lchild == NULL && T->rchild == NULL) {
return 1;
}
return LeafCount(T->lchild) + LeafCount(T->rchild);
}
第二题:
int Depth(BiTree T) {
if (T == NULL) {
return 0;
}
int leftDepth = Depth(T->lchild);
int rightDepth = Depth(T->rchild);
return (leftDepth > rightDepth ? leftDepth : rightDepth) + 1;
}
收藏
扫描二维码,在手机上阅读
推荐阅读: