二叉树的链式建立和返回叶子节点数,编译没问题但运行有问题??
程序代码:#include<stdio.h>
#include<malloc.h>
struct BTnode
{
char data;
struct BTnode *Lchild,*Rchild;
};
void CreateBTree(struct BTnode *B)
{
char ch=getchar();
if(ch=='a')
{
B=NULL;
}
else
{
B=(struct BTnode *)malloc(sizeof(struct BTnode));
B->data=ch;
CreateBTree(B->Lchild);
CreateBTree(B->Rchild);
}
}
int Countleaf(struct BTnode *B)
{
if(B==NULL) return 0;
if(B->Lchild==NULL&&B->Rchild==NULL) return 1;
return(Countleaf(B->Lchild)+Countleaf(B->Rchild));
}
void main()
{
struct BTnode B;
CreateBTree(&B);
Countleaf(&B);
}






