使用前序遍历

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
}
复制代码