main.c
// 295有序表的合并去重
//
// Created by 曹一典 on 2021/11/12.
//
#include <stdio.h>
#include <stdlib.h>
typedef struct Node{
int data;
struct Node *pNext;
}NODE,*PNODE;
PNODE Ini(void){
PNODE pHead;
pHead=(PNODE)malloc(sizeof(NODE));
pHead->pNext=NULL;
return pHead;
}
void Create(PNODE pHead,int n){
PNODE p=pHead;
for(int i=0;i<n;i++){
PNODE pNew=(PNODE)malloc(sizeof(NODE));
scanf("%d",&pNew->data);
pNew->pNext=NULL;
p->pNext=pNew;
p=p->pNext;
}
}
void Merge(PNODE L1,PNODE L2,PNODE L3){
PNODE a,b,c;
a=L1->pNext;
b=L2->pNext;
c=L3=L1;
while(a&&b){
if(a->datadata){
c->pNext=a;
c=a;
a=a->pNext;
//c=c->pNext;
}
else if(a->data>b->data){
c->pNext=b;
c=b;
b=b->pNext;
//c=c->pNext;
}
else{
/* c->pNext=b;*/
c->pNext=a;
c=a;
a=a->pNext;
b=b->pNext;
//c=c->pNext;
// c=c->pNext;
}
c->pNext=a?a:b;
L1->pNext=NULL;
L2->pNext=NULL;
//free (L2);
}
}
void output(PNODE m){
PNODE n=m->pNext;
while(n){
printf("%d",n->data);
n=n->pNext;
}
}
int main(int argc, const char * argv[]) {
int a,b;
scanf("%d %d",&a,&b);
PNODE p1=Ini();
PNODE p2=Ini();
PNODE p3=Ini();
Create(p1, a);
Create(p2, b);
Merge(p1,p2,p3);
//output(p1);
//output(p2);
output(p3);
return 0;
}