Hi,
Here is my code,
#include<stdio.h>
#include<stdlib.h>
typedef struct BiTNode
{
char data;
struct BiTNode *lchild,*rchild;
}BiTNode;
void CreateBiTree(BiTNode*);
void PreOrder(BiTNode*);
int main(void)
{
BiTNode *p;
p=NULL;
CreateBiTree(p);
printf("%d\n",p);
PreOrder(p);
system("PAUSE");
return 0;
}
void CreateBiTree(BiTNode* t)
{
char ch;
ch=getche();
printf("\n");
if(ch==' ')t=NULL;
else
{
t=(BiTNode*)malloc(sizeof(BiTNode));
printf("%d\n",t);
if(t==NULL)exit(-1);
t->data=ch;
puts("left child");
CreateBiTree(t->lchild);
puts("right child");
CreateBiTree(t->rchild);
}
}
void PreOrder(BiTNode* t)
{
if(t!=NULL)
{
printf("%c ",t->data);
PreOrder(t->lchild);
PreOrder(t->rchild);
}
}
I create the tree recursively,but in main function,the pointer is
NULL.Could anyone help me to build a binary tree with recursion?Thank
you!