//二叉数组的输出
void DisBTree(BTNode* bt)
{
if(bt)
{
DisBTree(bt->lchild);
DisBTree(bt->rchild);
printf("%c ""\n",bt->data);
}
}
//二叉数组的高度
int BTHeight(BTNode *bt)
{
int lchilddep,rchilddep;
if(bt == NULL)
return 0; //递归终止条件
else
{
lchilddep = BTHeight(bt->lchild);
rchilddep = BTHeight(bt->rchild);
return (lchilddep>rchilddep)?(lchilddep+1):(rchilddep+1);
}
}
//二叉数的结点个数
int NodeCount(BTNode *bt)
{
int num1,num2; //用来存放返回的值
if(bt == NULL)
return 0;
else
{
num1 = NodeCount(bt->lchild);
num2 = NodeCount(bt->rchild);
return (num1+num2+1);
}
}
//二叉树的叶子结点数
int LeafCount(BTNode *bt)
{
int num1,num2;
if(bt == NULL)
return 0;
else if(bt->lchild==NULL&&bt->rchild==NULL)
return 1;
else
{
num1 = LeafCount(bt->lchild);
num2 = LeafCount(bt->rchild);
return num1+num2;
}
}
<pre name="code" class="cpp">//二叉数组的输出(括号表示法输出)
void DispBTree(BTNode *bt)
{
if(bt!=NULL)
{
printf("%c",bt->data);
if(bt->lchild!=NULL||bt->rchild!=NULL)
{
printf("(");
DispBTree(bt->lchild);
if(bt->rchild!=NULL)
printf(",");
DispBTree(bt->rchild);
printf(")");
}
}
}