#include<stdio.h>
typedef struct BiNode {
char data;
struct BiNode* lchild, * rchild;
} BiNode, *BiTree;
void createBiTree(BiTree& T) {
char n;
printf( "请输入当前结点字母,#表示NULL:\n ");
scanf("%c",&n);
if (n == '#') {
T = NULL;
} else {
BiNode* node = new BiNode;
node->data = n;
T = node;
createBiTree(T->lchild);
createBiTree(T->rchild);
}
}
void preorder(BiTree T) {
if (T == NULL) return;
else {
printf("%c", T->data);
preorder(T->lchild);
preorder(T->rchild);
}
}
int fun(BiTree T) {
if (T == NULL) return 0;
else if (T->lchild == NULL && T->rchild == NULL)
return 1;
else
return fun(T->lchild) + fun(T->rchild);
}
int main() {
BiTree T = NULL;
createBiTree(T);
preorder(T);
printf("\n叶子节点数量为 %d\n",fun(T));
return 0;
}

typedef struct BiNode {
char data;
struct BiNode* lchild, * rchild;
} BiNode, *BiTree;
void createBiTree(BiTree& T) {
char n;
printf( "请输入当前结点字母,#表示NULL:\n ");
scanf("%c",&n);
if (n == '#') {
T = NULL;
} else {
BiNode* node = new BiNode;
node->data = n;
T = node;
createBiTree(T->lchild);
createBiTree(T->rchild);
}
}
void preorder(BiTree T) {
if (T == NULL) return;
else {
printf("%c", T->data);
preorder(T->lchild);
preorder(T->rchild);
}
}
int fun(BiTree T) {
if (T == NULL) return 0;
else if (T->lchild == NULL && T->rchild == NULL)
return 1;
else
return fun(T->lchild) + fun(T->rchild);
}
int main() {
BiTree T = NULL;
createBiTree(T);
preorder(T);
printf("\n叶子节点数量为 %d\n",fun(T));
return 0;
}
