二叉の木の中の度が0、1、2の結点の個数なことを求めます.
755 ワード
void leaf(btree* T,int &count)//count
{
if(T == NULL) //
return;
if(T->lchild == NULL&&T->rchild == NULL)// == &&
count++;
leaf(T->rchild,count);//
leaf(T->lchild,count);
}
/* 1 */
void degree1(btree* T,int &count)
{
if(T == NULL)
return;
if((T->lchild == NULL &&T->rchild != NULL)||(T->rchild == NULL &&T->lchild != NULL))
count++;
degree1(T->lchild,count);
degree1(T->rchild,count);
}
/* 2 */
void degree2(btree *T,int &count)
{
if(T == NULL)
return;
if(T->lchild != NULL&&T->rchild != NULL)
count++;
degree2(T->lchild,count);
degree2(T->rchild,count);
}