完整代码
typedef struct BiTree{
char data;
BiTree *lchild;
BiTree *rchild;
}BiTree;
BiTree* PreInCreate2(char pre[],char in[],int s1,int end1,int s2,int end2){
BiTree *root=(BiTree*)malloc(sizeof(BiTree));
root->data=pre[s1];
int i;
for(i=s2;in[i]!=root->data;i++);
int left=i-s2;
int right=end2-i;
if(left){
root->lchild=PreInCreate2(pre,in,s1+1,s1+left,s2,s2+left-1);
}else{
root->lchild=NULL;
}
if(right){
root->rchild=PreInCreate2(pre,in,end1-right+1,end1,end2-right+1,end2);
}else{
root->rchild=NULL;
}
return root;
}