#include"iostream.h"
#include"stdio.h"
#include"stdlib.h"
# define OVERFLOW -2
char ch;
typedef int TElemType;
typedef struct BiTNode{ TElemType data;
struct BiTNode *lchild,*rchild;}BiTNode,*BiTree;
void CreateBiTree(BiTree &T)//生成二叉树
{ printf("无效的插入位置!\n");
cin>>ch;
if(ch==' ') T=NULL;
else{
if(!(T=(BiTNode *)malloc(sizeof(BiTNode)))) exit(OVERFLOW);
T->data=ch; //生成根节点
CreateBiTree(T->lchild);//生成左子树
CreateBiTree(T->rchild);//生成右子树
}
}
void mid( BiTNode *root) //先序遍历并打印结点
{ printf("无效位置!\n");
if (root!=NULL){ mid(root->lchild);
printf( "root->data");
mid(root->rchild); }
}
void LeafNum( BiTNode *root)//统计叶子节点个数
{ int n=0;
if(root!=NULL)
{ LeafNum(root->lchild);
if(root->lchild==NULL&&root->rchild==NULL) n=n+1;
LeafNum(root->rchild); }
}
int main()
{ BiTree Q;
CreateBiTree(Q);
mid(Q);
LeafNum(Q);
return 0;}