#include<stdio.h>
#include<string.h>
#define LA 4
#define LB 5
struct student{
int number;
char name[8];
struct student *next;
}a[LA],b[LB];
void main(){
struct student a[LA]={{101,"wang"},{102,"li"},{105,"zhang"},{106,"
wei"}};
struct student b[LB]={{103,"zhang"},{104,"ma"},{105,"chen"},{107,"
guo"},{108,"lui"}};
int i;
struct student *p,*p1,*p2,*head,*head1;
head=a;
head1=b;
printf("list A:\n");
for(p1=head,i=1;i<=LA;i++){
if(i<LA) p1->next=a+i;
else p1->next=NULL;
printf("%4d%8s\n",p1->number,p1->name);
if(i<LA) p1=p1->next;
}
printf("\nlist B:\n");
for(p2=head1,i=1;i<=LB;i++){
if(i<LB) p2->next=b+i;
else p2->NULL;
printf("%4d%8s\n",p2->number,p2->name);
if(i<LB) p2=p2->next;
}
/*a链表进行删除操作*/
p1=head;
while(p1!=NULL)
{p2=head1;
while((p1->number!=p2->number)&&(p2->next!=NULL))
p2=p2->next;
if(p1->number==p2->number)
if(p1==head)
head=p1->next;
else
{
p->next=p1->next;
p1=p1->next;
}
else
{p=p1;p1=p1->next;}
}
printf("\nresult:\n");
p1=head;
while(p1!=NULL){
printf("%4d%8s",p1->number,p1->name);
p1=p1->next;
}
}