Combine two increasing ordered lists into one increasing ordered list. The resulting linked list still uses the storage space of the original two linked lists and does not occupy additional storage space. No duplicate data is allowed in the table.

#include<stdio.h> #include<malloc.h> typedef struct list { int data; struct list * next; // next node address}list; Struct list * L=NULL; Struct list * head=NULL; Struct list * p=NULL; Struct list * L1=NULL; Struct list * head1=NULL; Struct list * p1=NULL; Struct list * L2=NULL; Struct list * q=NULL; Struct list * q1=NULL; Int main(){int I =0,length; Printf (" Please enter the length of the linked list \n"); scanf("%d",&length); head=(struct list *)malloc(sizeof(struct list)); L=head; Printf (" Please enter the contents of the linked list \n"); for(i; i<length; i++){ p = (struct list *)malloc(sizeof(struct list)); scanf("%d",&p->data); p->next=NULL; head->next=p; head=p; } int i1=0,length1; Printf (" Please enter the length of the linked list \n"); scanf("%d",&length1); head1=(struct list *)malloc(sizeof(struct list)); L1=head1; Printf (" Please enter the contents of the linked list \n"); for(i1; i1<length1; i1++){ p1= (struct list *)malloc(sizeof(struct list)); scanf("%d",&p1->data); p1->next=NULL; head1->next=p1; head1=p1; } L2=(struct list *)malloc(sizeof(struct list)); q=L2; P =L->next; p1=L1->next; while(p&&p1){ if(p->data<p1->data){ L2->next=p; L2=p; p=p->next; }else if(p->data==p1->data){ L2->next=p; L2=p; p=p->next; q1=p1->next; // The next address of the alternate same element points to free(p1); p1=q1; }else if(p->data>p1->data){ L2->next=p1; L2=p1; p1=p1->next; } } L2->next=p? p:p1; free(L1); Printf (" contents of the merged list \n"); p=q->next; while(p){ printf("%d ",p->data); p=p->next; }}Copy the code