#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
using
namespace
std;
struct
Entry
{
int
m;
Entry *next;
};
Entry *GetNewEntry(){
int
p;
cin>>p;
Entry *newOne=
new
Entry;
newOne->m=p;
newOne->next=NULL;
return
newOne;
}
Entry *BuildList(
int
n)
{
Entry *listHead=NULL;
Entry *p=NULL;
while
(n>0)
{
Entry *newOne=GetNewEntry();
n--;
if
(p==NULL)
{
p=newOne;
listHead=p;
}
else
{
p->next=newOne;
p=p->next;
}
}
return
listHead;
}
Entry *mergeList(Entry *list1,Entry *list2)
//递归实现
{
if
(list1==NULL)
{
return
list2;
}
else
if
(list2==NULL)
{
return
list1;
}
Entry *list=NULL;
if
(list1->m<=list2->m)
{
list=list1;
list->next=mergeList(list1->next,list2);
}
else
{
list=list2;
list->next=mergeList(list1,list2->next);
}
return
list;
}
void
PrintEntry(Entry *m)
{
cout<<m->m;
}
void
PrintList(Entry *list)
{
if
(list==NULL){
cout<<endl;
}
else
{
PrintEntry(list);
if
(list->next!=NULL)
{
cout<<
" "
;
}
PrintList(list->next);
}
}
int
main()
{
int
m,n;
while
(cin>>m>>n)
{
if
(m==0&&n==0){
cout<<
"NULL"
<<endl;
}
else
{
vector<
int
> strList;
Entry *p=BuildList(m);
Entry *q=BuildList(n);
Entry *list=mergeList(p,q);
PrintList(list);
}
}
return
0;
}
/**************************************************************
Problem: 1519
User: 无梦楼主lv
Language: C++
Result: Accepted
Time:450 ms
Memory:4688 kb
****************************************************************