二叉链表储存二叉树叶节点的权值

使用前序遍历

int WPL(BiTree root)
{
    return wpl_PreOrder(root,0)
}

int wpl_PreOrder(BiTree root,int deep)
{
    static int wpl=0;
    if(root->lchild==NUll&&root->rchild==NULL)
        wpl+=deep*root->weight;
    if(root->lchild!=null)
        wpl_PreOrder(root->lchild,deep+1)
        if(root->rchild!=null)
        wpl_PreOrder(root->rchild,deep+1)
        return wpl
}
复制代码
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务