现二叉树用二叉链表表示,试编写一算法求解一棵二叉树的叶子总数(可采用递归算法描述)。
【正确答案】
void countleaf(bitreptr t,int * count)
{
if(t!=NULL)
{
if((t->lchild==NULL) && (t->rchild==NULL))
*count++;
countleaf(t->lchild,count);
countleaf(t->rchild,count);
}
}
【答案解析】
提交答案
关闭