假设二叉树采用二叉链表存储,其结点结构是(lchild,data,rchild)。试写出求二叉树叶子结点总数的算法。

论坛 期权论坛 期权     
O鸟无生趣   2018-4-26 14:03   5127   1
叶子结点的总数作为函数的返回值,函数头为:int IsBSt(BtreeNode *BT)。
分享到 :
0 人收藏

1 个回复

倒序浏览
2#
躬行问答  1级新秀 | 2018-4-30 01:54:00 发帖IP地址来自
/*  求叶子数  */
int IsBSt(BtreeNode *BT)
{
    int count1,count2;
    if(BT==NULL)
        return 0;
    else
    {
        if(BT->lchild==NULL && BT->rchild==NULL)
            return 1;
        else
        {
            count1=leafcount(BT->lchild);
            count2=leafcount(BT->rchild);
            return count1+count2;
        }
    }
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:
帖子:
精华:
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP