文章
316
粉丝
0
获赞
0
访问
47.5k
 
1):采用递归的思想,记录深度以及找到叶子结点,让其的权值乘以当前深度,然后返回求和
2):
typedef struct{
int*right;
int*left;
int weight;
}TNode*;
3):
int WPL(TNode*root,int high){//递归计算wpl
if(root==NULL)return0;
if(root->left!=NULL ll root->right!=NULL)//如果是非叶子结点就递归处理
return WPL(root->left,high+1)+WPL(root->right,high+1);
return (root->weight)*high;//如果是叶子结点就用当前高度乘以它的权值;
}
&...
登录后发布评论
暂无评论,来抢沙发