#include <stdlib.h>
#include <stdio.h>
#define maxsize 100
typedef char datatype;
typedef struct node {
datatype data;
struct node *lchild, *rchild;
} bitree;
bitree *CreateBiTree( ) {
bitree *T = NULL;
char ch;
ch = getchar( );
if (ch != '@') {
T = (bitree *)malloc(sizeof(bitree));
T->data = ch;
T->lchild = CreateBiTree();
T->rchild = CreateBiTree();
} else {
T = NULL;
}
return T;
}
int count = 0;
int countleaf(bitree *p) {
if (p != NULL) {
count = countleaf(p->lchild);
if (p->lchild == NULL && p->rchild == NULL) {
count = count + 1;
printf("%c", p->data);
}
count = countleaf(p->rchild);
}
return count;
}
int main() {
bitree *p;
printf("建立树,按先序遍历序列输入结点\n");
printf("空结点为@,结束按回车\n");
p = CreateBiTree( );
printf("叶子结点为: ");
countleaf(p);
printf("\n叶子结点数目为:%d\n ", count);
return 0;
}