#include <iostream>
#include <vector>
#include <string>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef struct node
{
int data;
node *lchild,*rchild;
}TreeNode,* BTree;
void Pre(BTree root)
{
if(root==NULL)
return ;
else
{
printf("%d ",root->data);
Pre(root->lchild);
Pre(root->rchild);
}
}
BTree ReBuild(int *a,int *b,int n)
{
BTree root;
root = (BTree)malloc(sizeof(TreeNode));//注意一定要先创建一个实例
root->lchild=NULL;
root->rchild=NULL;
if(n>=1)
{
root->data=b[n-1];
int i;
for(i=0;i<n&&a[i]!=b[n-1];i++);
root->lchild=ReBuild(a,b,i);
root->rchild=ReBuild(a+i+1,b+i,n-i-1);
return root;//迭代出口
}
else
return NULL