当前位置:首页 > 数据结构(02331) > 正文内容

二叉树的存储结构类型定义如下:
typedefstructnode{
intdata;
structnode*lchild,*rchild;
}BinNode;typedefBinNode*BinTree;编写递归算法,求只有一个孩子结点的结点总
数,并计算这些结点的数据值的和。
函数的原型为:voidt34(BinTreeT,int*count,int*sum)
*count和*sum的初值为0。

高老师2年前 (2024-03-26)数据结构(02331)8

二叉树的存储结构类型定义如下:
typedefstructnode{
intdata;
structnode*lchild,*rchild;
}BinNode;typedefBinNode*BinTree;编写递归算法,求只有一个孩子结点的结点总
数,并计算这些结点的数据值的和。
函数的原型为:voidt34(BinTreeT,int*count,int*sum)
*count和*sum的初值为0。

void f34(BinTree T,int * count,int * sum) { if(T) {if((T一>lchild&&(!T一>rchild))∣|((!T一>lchild)&&T一>rchild)) { (*count)++; *sum+=T一>data; } f34(T一>lchild,count,sum); f34(T一>rchild,count,sum); } }

扫描二维码免费使用微信小程序搜题/刷题/查看解析。

版权声明:本文由翰林刷题小程序授权发布,如需转载请注明出处。

本文链接:https://doc.20230611.cn/post/432136.html

分享给朋友: