函数怎么执行有错误?
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "conio.h"
struct student
{
long num;
float score;
struct student *next;
};
struct student *del(struct student *head1,struct student *head2)
{
struct student *p1,*p2,*p3;
for(p2=head2;p2!=NULL;p2=p2->next)
{
for(p1=head1;p1!=NULL;p3=p1,p1=p1->next)
{
if(p1->num==p2->num)
{
if(p1==head1) head1=p1->next;
else p3->next=p1->next;
}
}
}
return(head1);
}
struct student *del1(struct student *head1,struct student *head2)//我要查找两个链表的相同元素,然后将相同的元素删除?第一个链表能够删除,第二个链表不能删除,代码该如何编写?
{
struct student *p1,*p2,*p3;
for(p2=head2;p2!=NULL;p2=p2->next)
{
for(p1=head1;p1!=NULL;p3=p1,p1=p1->next)
{
if(p2->num=p1->num)
{
if(p2==head2)
head2=p2->next;
else
p2=p2->next;
}
}
return (head2);
}
}
int main(int argc, char* argv[])
{
struct student a,b,c,d,e,f,*head1,*head2,*p,*q,*w;
a.num=99101;a.score=89;
b.num=99102;b.score=90;
c.num=99103;c.score=91;
head1=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head1;
printf("Linklist 1:\n");
while(p!=NULL)
{
printf("%ld%5.1f\n",p->num,p->score);
p=p->next;
}
printf("\n");
d.num=99103;d.score=92;
e.num=99104;e.score=93;
f.num=99105;f.score=94;
head2=&d;
d.next=&e;
e.next=&f;
f.next=NULL;
q=head2;
printf("Linklist:\n");
while(q!=NULL)
{
printf("%ld%5.1f\n",q->num,q->score);
q=q->next;
}
printf("\n");
head1=del(head1,head2);
printf("delete Linklist 1:\n");
for(p=head1;p!=NULL;p=p->next)
{
printf("%ld%5.1f\n",p->num,p->score);
}
printf("\n");
head2=del(head1,head2);
printf("delete Linklist 2:\n");
for(q=head2;q!=NULL;q=q->next)
{
printf("%ld%5.1f\n",q->num,q->score);
}
return 0;
}