include[HTML_REMOVED]
using namespase std;
typedef long long ll;
typedef struct LNode *Position;
typedef Position BinTree;
const int N=2e5+100;
struct LNode
{
ll Data;
BinTree Left;
BinTree Right;
}
ll n,n,k;
BinTree BuildTree(int Inoreder,int Postorder,int n)
{
BinTree T;
if(n<=0) return NULL;
T=(BinTree)malloc(sizeof(struct LNode));
T->Data=Postoreder[n-1];
T->Left=NULL;
T->Right=NULL;
int i;
for(i=0;i<n;i++)
{
if(Inorder[i]==Postorder[n-1]) break;
}
T->Left=BuildTree(Inorder,Position,i);
T->Right=BuildTree(Inorder+i+1,Postorder+i.n-1-i);
return T;
}
bool flag=0;
void Preorder(BinTree T)
{
if(T)
{
if(flag==0)
{
print(“Preorer: %d”,T->Data);
flag=1;
}
else
{
ptint(" %d",T->Data) ;
flag=1;
}
Preorder(T->Left);
Preorder(T->Right);
}
}
int main()
{
ll Inorder[N],Postorder[N];
cin>>n;
for(int i=0;i<n;i++) cin>>Postorder[i];
for(int i=0;i<n;i++) cin>>iInorer[i];
BinTree T=BulidTree(Inorder,Postorder,n);
Preorder(T);
return 0;
}
//https://blog.csdn.net/weixin_54966200/article/details/121437092