文章目录

PTA第六章树答案参考

由 浪浪猪 发布

第一题:

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;
}


收藏

扫描二维码,在手机上阅读

0条评论

发表评论