#include #define Length sizeof(struct node)
typedef struct node
{int data;
struct node *next;
}Lnode;
Lnode *init(Lnode *head) //多组数据输入要用init清空上一组
{
head=(Lnode*)malloc(Length);
if(head!=NULL)
{
head->next=NULL;
return head;
}
}
void increase(Lnode* head, int e ) //数据输入用了一个生成递增有序链表的函数 直接在输入时排序
{Lnode *p,*q,*f;
q=head;
p=head->next;
while(p&&e>p->data)
{q=p;
p=p->next;
}
f=(Lnode*)malloc(Length);
f->data=e;
f->next=p;
q->next=f;
}
struct node *merge(Lnode *La,Lnode *Lb)
{Lnode *pa,*pb,*pc;
pa=La->next ;pb=Lb->next ;
pc=La;
free(Lb);
while(pa&&pb)
{if(pa->data<=pb->data)
{pc->next=pa;
pc=pa;
pa=pa->next;
}
else
{pc->next=pb;
pc=pb;
pb=pb->next;
}
}
if(pa)
pc->next=pa;
else
pc->next=pb;
return La;
}
void print(Lnode *head)
{ Lnode *p;
p=head->next;
int flag=1;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int main()
{int m,n,x,i;
Lnode *A,*B,*C,*p;
A=(Lnode*)malloc(Length);
B=(Lnode*)malloc(Length);
A->next=NULL;
B->next=NULL;
while(scanf("%d",&m)!=EOF)
{A=init(A);
B=init(B);
for(i=1;i<=m;i++)
{scanf("%d",&x);
increase(A,x);
}
scanf("%d",&n);
for(i=1;i<=n;i++)
{scanf("%d",&x);
increase(B,x);
}
{C=merge(A,B);
print(C);}
}
return 0;}