编写一个递归算法,计算二叉树中度为1的结点数目

如题所述

int Degrees1(BitNode *t)
{
if(t==NULL) return 0;
if(t->lchild !=NULL && t->rchild==NULL || t->lchild ==NULL && t->rchild!=NULL)
return 1+Degrees1(t->lchild)+Degress1(t->rchild);
return Degrees1(t->lchild)+Degress1(t->rchild);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-06-24
数据结构
bool hasdegree1(BiTree root){
if(root==NULL)
return false;
if(root->lchild==NULL&&root->rchild==NULL)
return false;
if(root->lchild!=NULL&&root->rchild!=NULL)
return hasdegree1(root->lchild)||hasdegree1(root->rchild);
else return true;
}
第2个回答  2011-10-16
不用递归,数一下有多少个叶子节点就可以了
第3个回答  2011-10-16
这不需要递归吧 遍历一下就行了
相似回答