void restoretree(BiNode
{
if(n <= 0) return ;
bt = new BiNode
T *p;
int k;
bt->data = *preo;
for(p = ino; p < ino + n; ++p)
if(*p == *preo) break;
k = p - ino;
restoretree(bt->left,preo+1,ino,k);
restoretree(bt->right,preo+k+1,p+1,n-k-1);
}
int FindStr(char *,char);
BiTreeNode Create_PI_Item(char *pre,char *in)
{
if('\0'==*pre||'\0'==*in)return NULL;
else
{
char *pp=new char[strlen(pre)+1];
char *ii=new char[strlen(pre)+1];
BiTreeNode root=BuyNode();
root->elem=*pre;
int local=FindStr(in,*pre);
strncpy(pp,pre+1,local);
pp[local]='\0';
strncpy(ii,in,local);
ii[local]='\0';
root->LfChild=Create_PI_Item(pp,ii);
strcpy(pp,pre+local+1);
strcpy(ii,in+local+1);
root->RgChild=Create_PI_Item(pp,ii);
delete []pp;
delete []ii;
return root;
}
}
int FindStr(char *S,char ch)
{
if(S!=NULL && *S!='\0')
{
for(int i=0;i<(int)strlen(S);++i)
{
if(S[i]==ch)
{
return i;
}
}
}
return -1;
}