以二叉链表为存储结构,分别写出求二叉树结点总数,叶子总数及树的高度的算法,输出此树中序遍历的序列

2024-12-05 06:46:08
推荐回答(1个)
回答1:

int CountNode (BTNode *t) //节点总数
{
int num;
if (t == NULL)
num = 0;
else
num = 1 + CountNode (t->lch) + CountNode (t->rch);
return (num);
}

void CountLeaf (BTNode *t) //叶子节点总数
{
if (t != NULL)
{
if (t->lch == NULL && t->rch == NULL)
count ++; // 全局变量
CountLeaf (t->lch);
CountLeaf (t->rch);
}
}