根据先序和中序建立二叉树主要考察的是对树前序和中序遍历的理解,然后根据反过来递归上去
struct Tree
{
int value; Tree* lchild,* rchild;
}BTree;
int Find(int *zhong,int x,int len) {
for(int i=0;i<len;i++) {
if(zhong[i]==x) {
return i;
}
}
}
Tree* build(int *zhong,int *xian,int len) {
if(len<=0)
return NULL;
Tree *tmp=new Tree;
tmp->value=xian[0];
int index=Find(zhong,xian[0],len);
tmp->lchild=build(zhong,xian+1,index);
tmp->rchild=build(zhong+index+1,xian+index+1,len-index-1);
return tmp;
}