#include <stdio.h#include <stdlib.h#define new (struct node *)malloc(sizeof(struct node))struct node {int value;struct node *next;};struct node *creat(int a[],int n){struct node *head,*q;for (head=NULL;n;n--){q=(struct node *) malloc(sizeof(struct node));q-value=*a++;q-next=head;head=q;}return head;}struct node *copy(struct node *h){struct node *head,*p,*q,*u,*v;head=NULL;p=h;while (p){q=(struct node *) malloc(sizeof(struct node));q-value=p-value;v=head;while (v-value<q-value && v!=NULL){u=v;v=v-next;}if (v==head)head=q;else u-next=q;q-next=v;p=p-next;}return head;}int d[]={1,7,3,5};int b[]={2,4,8,0};struct node *connect(struct node *h1,struct node *h2){struct node *h3,*pa,*pb,*p,*q,*r;h3=(struct node *)malloc(sizeof(struct node));p=h3;pa=h1-next;free(h1);pb=h2-next;free(h2);while (pa!=NULL && pb!=NULL){q=(struct node *)malloc(sizeof(struct node));if(pb-valuevalue){q-value=pb-value;pb=pb-next;}else{q-value=pa-value;pa=pa-next;if(pa-value==pb-value){r=pb;pb=pb-next;free(r);}}p-next=q;p=q;}while(pa!=NULL){q=(struct node *)malloc(sizeof(struct node));q-value=pa-value;pa=pa-next;p-next=q;p=q;}while(pb!=NULL){q=(struct node *)malloc(sizeof(struct node));q-value=pb-value;pb=pb-next;p-next=q;p=q;}p-next=NULL;return(h3);}main(){struct node *h1,*h2,*p,*t,*l;h1=creat(d,sizeof d/sizeof d[0]);p=copy(h1);while(p){printf("%5d",p-value);p=p-next;}printf("\n");h2=creat(b,sizeof b/sizeof b[0]);t=copy(h2);while(t){printf("%5d",t-value);t=t-next;}printf("\n");l=connect(p,t);while(l){printf("%5d",l-value);l=l-next;}printf("\n");}