#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct node
{
int data;
struct node*lchild;
struct node*rchild;
}BiTNode,*BiTree;
void creat(BiTree*root)
{
int ch;
scanf("%d",&ch);
if(ch==-1)
{
*root=NULL;
}
else
{
*root=(BiTree)malloc(sizeof(BiTNode));
(*root)->data=ch;
creat(&((*root)->lchild));
creat(&((*root)->rchild));
}
}
void insert(BiTree *root,int c)
{
BiTree s;
if(*root==NULL)
{
s=(BiTree)malloc(sizeof(BiTNode));
s->data=c;
s->lchild=NULL;
s->rchild=NULL;
*root=s;
}
else if(c<(*root)->data)
insert(&(*root)->lchild,c);
else if(c>(*root)->data)
insert(&(*root)->rchild,c);
}
void inorder(BiTree root)
{
if(root!=NULL)
{
inorder(root->lchild);
printf("%d ",root->data);
inorder(root->rchild);
}
}
void combine(BiTree T1,BiTree T2)
{
if(T2!=NULL)
{
insert(&T1,T2->data);
combine(T1,T2->lchild);
combine(T1,T2->rchild);
}
}
int main()
{
BiTree root1=NULL;
BiTree root2=NULL;
creat(&root1);
creat(&root2);
combine(root1,root2);
inorder(root1);
printf("\n");
return 0;
}