#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define max 50
typedef struct tree{
struct tree *LChild;
char data;
struct tree *RChild;
}BitNode,*BiTree;
BiTree creatree(BiTree root,char*Data){
static int flag=1;
static int i = 0;
if(Data[i]==' '){
root = NULL;
i++;
return 0;
}
if(flag!=1){root = (BitNode*)malloc(sizeof(BitNode));}
root->data = Data[i];
//root->LChild = (BitNode*)malloc(sizeof(BitNode));
//root->RChild = (BitNode*)malloc(sizeof(BitNode));
i++;
flag=0;
creatree(root->LChild,Data);
creatree(root->RChild,Data);
}
//先序遍历
void PreOrder(BiTree root){
if(root!=NULL){
printf("%c",root->data);
PreOrder(root->LChild);
PreOrder(root->RChild);
}
}
//中序遍历
void InOrder(BiTree root){
if(root!=NULL){
InOrder(root->LChild);
printf("%c",root->data);
InOrder(root->RChild);
}
}
//后序遍历
void PostOrder(BiTree root){
if(root!=NULL){
PostOrder(root->LChild);
PostOrder(root->RChild);
printf("%c",root->data);
}
}
int main(){
BiTree root;
BiTree head;
char *Data;
Data=(char*)malloc(sizeof(char)*max);
gets(Data);
head =root = (BitNode*)malloc(sizeof(BitNode));
creatree(root,Data);
PreOrder(head);
return 0;
}
这代码有什么问题?