统计二叉树的高度的c语言程序,如何用c语言计算二叉树结点数,叶子结点数,高度....

2014-04-08 回答

#include

#include

/*求二叉树叶子结点的数目*/

typedef struct bitnode

{

char data;

struct bitnode * lchild,* rchild;

}bitnode,* bitree;

//???问题一:* bitree是数据类型名吗?可不可说是struct bitnode别名???  //就是这样的   建议看看啊typedef

int creatbitree(bitree t)

{

//问题二:此处的为什么是*t而不是&t???    //请注意bitree是指针类型

char ch;

scanf("%c",&ch);

if(ch=='#')

t=null;

else

{

t=(bitnode *)malloc(sizeof(bitnode));

if(t==null)return 0;

t->data=ch;

creatbitree(t->lchild);

creatbitree(t->rchild);

}

return 1;

}

int number(bitree b)

{

//问题三:此函数是求叶子数目,如何修改啊?

if(b)

{

if( (b->rchild == null) && (b->lchild == null) )

return 1;

else

return number(b->lchild)+number(b->rchild);

}

else

return 0;

}

int main()

{

bitree t=null;

int s;

printf("please input binary tree:\n");

creatbitree(t);

if(!t)

printf("this is empt tree.");

else

{

printf("the number of binarytree'node is:");

s=number(t);

}

printf("\n");

printf("%d",s);

getch();

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值