#include "stdlib.h"
#include "stdio.h"
#define OVERFLOW -2
int i,j;
typedef int ElemType;
typedef struct Lnode{ ElemType elem;
struct Lnode *next;
int length;}Lnode,*LinkList;
LinkList p,q,pa,pb,pc,s,Lb,La,Lc;
ElemType temp;
void CreatList (LinkList L,int n)//生成一个带头节点的链表
{ i=0;
L=(LinkList)malloc(sizeof(Lnode));
if(!L) exit (OVERFLOW);
L->next=NULL;
while(i<n){ p=(LinkList)malloc(sizeof(Lnode));
if(!L) exit (OVERFLOW);
scanf("%c",&(*p).elem);
p->next=L->next;L->next=p;i++;
L->length=n;}
}
void Insert (LinkList L,int i,ElemType e)//在第i个节点前插入元素e
{ p=L; j=0;
while(j<i)
{p=p->next;j++;}
s=(LinkList)malloc(sizeof(Lnode));
if(!L) exit (OVERFLOW);
s->elem=e;s->next=p->next;p->next=s;}
void Delete(LinkList L,int i)//删除第i个节点
{ p=L; j=0;
while(j<i){ p=p->next; j++}
q=p->next;p->next=q->next;free(q);}
void AscendList(LinkList L)//将链表按递增序列排列
{for(i=(*L).length;i>0;i--)for(j=1;j<(*L).length;j++){p=L;p=p->next;
if( p->elem>=p->next->elem)
{ temp= p->next->elem; p->next->elem=p->elem; p->elem=temp;}
}
}
void MergeList(LinkList La,Lb,Lc)//合并La和Lb为Lc
{ Lc=(LinkList)malloc(sizeof(Lnode));
if(!Lc) exit (OVERFLOW);
pa=La;pb=Lb;pc=Lc;Lc->length=0;
pa=pa->next; pb=pb->next;
while(pa&&pb)
{if((*pa).elem<=(*pb).elem) { pc->next=pa;pa=pa->next;(*Lc).length++;}
else {pc->next=pb;pb=pb->next;(*Lc).length++;}
while(pa){ pc->next=pa;pa=pa->next;(*Lc).length++;}
while(pb){ pc->next=pb;pb=pb->next;(*Lc).length++;}
}
int main()
{ CreatList(La,7);
CreatList(Lb,6);
Insert (La,4,6);
Delete(Lb,3);
MergeList(La,Lb,Lc);
for(i=0;i<Lc->length;i++) {p=Lc;p=p->next;printf("%c",p->elem);}
return 0; }