#include<stdio.h>
#include<malloc.h>
#define NULL 0
typedef struct bitnode
{ char data;
struct bitnode *lchild;
struct bitnode *rchild;
}bitnode;
void (*visit)() /*define a function pointer*/
bitnode *CreatBitree(bitnode *T)
{ char ch;
bitnode *p=NULL;
p=(bitnode*)malloc(sizeof(bitnode));
printf("Enter letters:");
scanf("%c",&ch);
if(ch==' ')
{
p=NULL;
T=p;
}
else
{
if(!p)
printf("Init error!");
else
{
T=p;
T->data=ch;
T->lchild=CreatBittree(T->lchild);
T->rchild=CreatBittree(T->rchild);
}
}
return(T);
}
void PrintElem(char e)
{
printf("%c",e);
}
void PreTra(bitnode *T,visit)
{
if(T) visit(T->data);
if(T->lchild) PreTra(T->lchild,PrintElem);
if(T->rchild) PreTra(T->lchild,PrintElem);
else
printf("Can't visit rchild.");
}
void main()
{ bitnode *T;
bitnode *T1;
T1=CreatBitree(T);
PreTrv(T,PrintElem);
}