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;
}