编写算法

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:46:27
根据下面函数原形,编写一个递归算法,统计并返以BT为树跟指针的二叉书中所有叶子结点的个数.
int Count(BTreeNode* BT)

要快啊,过了今天明天就没分了.

int Count(BTreeNode* BT)
{
int nLeftLeave, nRightLeave;
if( (BT->Left == NULL) && (BT->Right == NULL) )
return 1; // leave node
if( BT->Left != NULL )
nLeftLeave = Count(BT->Left);
if( BT->Right != NULl)
nRightLeave = Count(BT->Right);
return nLeftLeave + nRightLeave;
}

虽然晚了点;不过我就是喜欢递归