#include?<stdio.h>?
#include?<string.h>
#include?<stdlib.h>?typedef?struct?linknode?
{?int?num;char?name[20];struct?linknode?*next;?
}node;?node?*creat()?
{?node?*h?=?NULL,*s,*t;int?d;int?i?=?1;?char?name1[20];while(1)?{?printf("輸入第%d結點的學號,姓名\n",i);?scanf("%d%s",&d,&name1);?if(d?==?0)break;?if(i?==?1)?{?h?=?(node?*)malloc(sizeof(node));?h->num?=?d;?strcpy(h->name,name1);h->next?=?NULL;?t?=?h;?}?else?{?s?=?(node?*)malloc(sizeof(node));?s->num?=?d;?strcpy(s->name,name1);s->next?=?NULL;?t->next?=?s;?t?=?s;}?i++;?}?return?h;?
}?
void?print(node?*h)?
{?node?*p?=?h;?if(p?==?NULL)?printf("空表\n");?while(p?!=?NULL)?{?printf("%d?%s\n",p->num,p->name);?p?=?p->next;?}?printf("\n");
}?node?*link(node?*ha,node?*hb)?
{?node?*r,*head,*s,*p,*q;?head?=(node?*)malloc(sizeof(node));?head->next?=?NULL;?r?=?head;?p?=?ha;?while(p!=NULL)?{?q?=?hb;?while((q?!=?NULL)?&&?(p->num?!=?q->num))?q?=?q->next;?if(q?!=?NULL)?{?r->next?=?p->next;?free(p);?p?=?r->next;?}?else?{?r->next?=?p;?r?=?p;?p?=?p->next;?r->next?=?NULL;?}?}?s?=?head;?head?=?head->next;?free(s);?return?head;?
}?
int?main()?
{?node?*ha,*hb,*s;?printf("\n請輸入鏈表a的信息,學號等于零時結束輸入:格式(學號?姓名)\n");ha?=?creat();printf("\n鏈表a的信息為:\n");print(ha);?printf("\n請輸入鏈表b的信息,學號等于零時結束輸入:格式(學號?姓名)\n");hb?=?creat();?printf("\n鏈表b的信息為:\n");print(hb);?s?=?link(ha,hb);?printf("\n刪除后的鏈表信息為:\n");print(s);return?0;?
}