利用先序遍历算法,统计在遍历二叉树的同时统计结点个数

假设有一棵二叉树,请试写一种算法,通过该算法可以统计二叉树中的结点数

typedef struct Node
{
    int data;
    struct Node* left;
    struct Node* right;
} Node;

int count_nodex(Node* head)
{
    return head == NULL ? 0 : 1 + count_nodex(head->left) + count_nodex(head->right);
}

 

int BiTreeCount(BiTree T)
{
    int rNum,lNum;
    if(!T)
        return 0;
    else
    {
        lNum = BiTreeCount(T->lchild);
        rNum = BiTreeCount(T->rchild);
        return rNum + lNum + 1;
    }
}