Exp6
#include <stdio.h>
typedef struct node
{ char data;
struct node *lchild,*rchild;
}BiNode,*BiTree;
int LeafCount(BiTree t)
{
if(t==NULL) return 0;
else if((t->lchild==NULL)&&(t->rchild==NULL)) return 1;
else return LeafCount(t->lchild)+LeafCount(t->rchild);
}
BiTree CreatBT()
{ BiTree t;
char c;
scanf("%c",&c);
if(c=='@')
return NULL;
else
{ t=(BiTree)malloc(sizeof(BiNode));
t->data=c;
t->lchild=CreatBT();
t->rchild=CreatBT();
return t;
}
}
void PreorderBT(BiTree t)
{ if(t)
{ printf("%c",t->data);
PreorderBT(t->lchild);
PreorderBT(t->rchild);
}
}
void InorderBT(BiTree t)
{ if(t)
{ InorderBT(t->lchild);
printf("%c",t->data);
InorderBT(t->rchild);
}