#include <malloc.h>
#include <iostream>
using namespace std;
#define error -1;
#define ok 1;
typedef int ElemType;
typedef int Status;
typedef struct LNode
{
    ElemType data;
    struct LNode *next;
}LNode,*LinkList;
Status GetElem(LinkList L,int i,ElemType &e)
{
   LinkList p;
   p=L->next;
   int j=1;
   while(p&&j<i)
   {
       p=p->next;
       ++j;
   }
   if(!p||j>i)
      return error;
   e=p->data;
   return ok;
}
Status ListInsert(LinkList &L,int i,ElemType e)
{
    LinkList p,s;
    p=L;
    int j=0;
    while(p&&j<i-1)
    {
        p=p->next;
        ++j;
    }
    if(!p||j>i-1)
       return error;
    s=(LinkList)malloc(sizeof(LNode));
    s->data=e;
    s->next=p->next;
    p->next=s;
    return ok;
}
Status ListDelete(LinkList &L,int i,ElemType &e)
{
    LinkList p,q;
    p=L;
    int j=0;
    while(p->next&&j<i-1)
    {
        p=p->next;
        ++j;
    }
    if(!(p->next)||j>i-1)   return error;
    q=p->next;
    p->next=q->next;
    e=q->data;
    free(q);
    return ok;
}
void CreatList(LinkList &L,int n)
{
    LinkList p;
    int i;
    L=(LinkList)malloc(sizeof(LNode));
    L->next=NULL;
    for(i=n;i>0;i--)
    {
        p=(LinkList)malloc(sizeof(LNode));
        cin>>p->data;
        p->next=L->next;
        L->next=p;
    }
}
void MergeList(LinkList &La,LinkList &Lb,LinkList &Lc)
{
    LinkList pa,pb,pc;
    pa=La->next;
    pb=Lb->next;
    Lc=pc=La;
    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;
        }
    }
    pc->next=pa?pa:pb;
    free(Lb);
}
int main()
{
 LNode La,Lb,Lc;
 LinkList pa,pb,pc;
 pa=La->next;
 pb=Lb->next;
 Lc=pc=La;
 int m,n,i,j,k;
 typedef int ElemType;
 ElemType e;
 cout<<"input m:";
 cin>>m;
 cout<<"input La:";
 CreatList(La,m);
 cout<<"input n:";
 cin>>n;
 cout<<"input Lb:";
 CreatList(Lb,n);
 MergeList(La,Lb,Lc);
 for(pc;!(pc->next);pc=pc->next)
    cout<<pc->data;
 cout<<"input i:";
 cin>>i;
 GetElem(La,i,e);
 cout<<"e="<<e<<endl;
 cout<<"input j:";
 cin>>j;
 ListInsert(La,j,e);
 cout<<"input La:";
 for(pa;!(pa->next);pa=pa->next)
    cout<<pa->data;
 cout<<"input k:";
 cin>>k;
 ListDelete(Lb,k,e);
 cout<<"input Lb:";
 for(pb;!(pb->next);pb=pb->next)
    cout<<pb->data;
 return 0;
}