1.求节点个数:
int btnum(btnode *p)
{if(p==NULL) return 0;
return btnum(p->lchild)+btnum(p->rchild)+1;
}
2.求度为一的节点个数:
int btnum1(btnode *T)
{
int n=0;
if(T==NULL)
return 0 ;
else if((T->lchild==NULL&&T->rchild!=NULL)||(T->lchild!=NULL&&T->rchild==NULL))
n=1;
return btnum1(T->lchild)+btnum1(T->rchild)+n;
}
3.求度为2的节点个数:
int btnum2(btnode *T)
{
int n=0;
if(T==NULL)
return 0 ;
else if(T->lchild!=NULL&&T->rchild!=NULL)
n=1;
return btnum2(T->lchild)+btnum2(T->rchild)+n;
}