求二叉树高度

int GetHeight(BinTree BT)
{
    if (BT == NULL)
        return 0;       //如果树为空返回0
    int hl = 0, hr = 0; //保存左右分支的高度
    hl = GetHeight(BT->Left) + 1;
    hr = GetHeight(BT->Right) + 1;
    return hl > hr ? hl : hr; //输出最高的分支
}

统计二叉树结点个数

int NodeCount(BiTree T)
{
    if (T == NULL)
        return 0;  //如果树为空返回0
    int count = 0; //保存树的结点数
    count = NodeCount(T->lchild) + NodeCount(T->rchild) + 1;
    //树的结点数=左节点+右节点
    return count;
}

统计二叉树度为1的结点个数

int NodeCount(BiTree T)
{
    if (T == NULL)
        return 0; //如果树为空返回0
    if ((T->lchild == NULL && T->rchild != NULL) || (T->lchild != NULL && T->rchild == NULL))
        //树的左儿子等于空与树的右儿子不等于空或树的左儿子为空与右儿子不为空
        return NodeCount(T->lchild) + NodeCount(T->rchild) + 1;
    else
        return NodeCount(T->lchild) + NodeCount(T->rchild);
}