#include<stdio.h>
#include<malloc.h>
#define SIZE 100
#define INCREMENT_SIZE 10
#define TRUE 1
#define FALSE -1
#define OK 1
#define ERROR -1
typedef int Status;
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LList;
Status create(LList *L,int n)
{
*L = (LNode*)malloc(sizeof(LNode));
(*L)->next = NULL;
LNode *p=*L;
for(int i=1;i<=n;i++)
{
ElemType t;
scanf("%d",&t);
p->next=(LNode*)malloc(sizeof(LNode));
p->next->data=t;
p=p->next;
}
p->next = NULL;
return OK;
}
Status MergeList_L(LList La,LList Lb,LList *Lc)
{
LNode *pa=La->next;
LNode *pb=Lb->next;
*Lc = (LNode*)malloc(sizeof(LNode));
(*Lc)->next = NULL;
LNode *pc=*Lc;
while(pa&&pb)
{
if(pa->data <= pb->data)
{
pc->next = pa;
pa = pa->next;
pc = pc->next;
}
else
{
pc->next = pb;
pb = pb->next;
pc = pc->next;
}
}
if(pa)
{
pc->next = pa;
}
else
{
pc->next = pb;
}
return OK;
}
Status Purge(LList *L)
{
LNode *p=(*L)->next;
while(p->next)
{
LNode *q=p;
if(q->data!=q->next->data)
{
p=p->next;
}
else
{
q=q->next;
p->next=q->next;
free(q);
}
}
}
Status Print(LList L){
LNode* p = L->next;
while(p){
printf("%d ",p->data);
p = p->next;
}
printf("\n");
return OK;
}
int main()
{
LList La, Lb, Lc;
create(&La,5);
create(&Lb,6);
MergeList_L(La,Lb, &Lc);
Purge(&Lc);
Print(Lc);
return 0;
}