实现一个函数,返回二叉树bt中所有度为2的结点的数值之和(不是求数量之和)!!!
函数接口定义:
int sumDCNodes(struct BinTree *bt);
实现一个函数,返回二叉树bt中所有度为2的结点的数值之和(不是求数量之和)!!!
函数接口定义:
int sumDCNodes(struct BinTree *bt);
int sumDCNodes( BinTree *bt) const{
int num = 0;
if(bt)
{
if(bt->GetLChild() && bt->GetRChild())
{
num = bt->data;
}
num = num + sumDCNodes(bt->GetLChild()) + sumDCNodes(bt->GetRChild());
}
return num;
}