用单链表求两集合交集,求大神帮忙看一下哪里错了,万分感谢
#include<stdio.h>typedef struct node1{
int data;
struct node *next1;
}*L1list;
typedef struct node2{
int data;
struct node *next2;
}*L2list;
void print(L1list L1,L2list L2);
int judge(int m,L2list L2);
void result(L1list head1);
void intersec(L1list A,L2list B);
int main()
{
int n,m,i;
L1list p1,r1,q1,head1;
L2list p2,r2,q2,head2;
head1=NULL;
head2=NULL;
printf("输入第一个数据\n");
scanf("%d",&n);
while(n!=0)
{
p1=(L1list)malloc(sizeof(L1list));
p1->data=n;
p1->next1=NULL;
if(head1==NULL)
{
head1=p1;
r1=p1;
}
else
{
r1->next1=p1;
r1=p1;
}
printf("输入下一个数\n");
scanf("%d",&n);
}
getchar();
printf("输入第二个数据\n");
scanf("%d",&m);
while(m!=0)
{
p2=(L2list)malloc(sizeof(L2list));
p2->data=m;
p2->next2=NULL;
if(head2==NULL)
{
head2=p2;
r2=p2;
}
else
{
r2->next2=p2;
r2=p2;
}
printf("输入下一个数\n");
scanf("%d",&m);
}
print(head1,head2);
intersec(head1,head2);
result(head1);
}
void result(L1list head1)
{
L1list p;
printf("A^B为\n");
while(p)
{
printf("%d",p->data);
p=p->next1;
}
}
void print(L1list L1,L2list L2)
{
L1list p1;
L2list p2;
p1=L1;
p2=L2;
printf("第一个链表为\n");
while(p1)
{
printf("%d",p1->data);
p1=p1->next1;
}
printf("第二个链表为\n");
while(p2)
{
printf("%d",p2->data);
p2=p2->next2;
}
}
void intersec(L1list A,L2list B)
{
L1list p,pr;
int n;
pr=A;
p=pr;
while(p)
{
n=p->data;
if(!judge(n,B))
{
pr->next1=p->next1;
free(p);
while(p->next1)
p=pr->next1;
}
else
{
pr=p;
p=p->next1;
}
}
}
int judge(int m,L2list L2)
{
L2list q;
q=L2;
if(q)
{
if(q->data==m)
return 0;
else
q=q->next2;
}
else return 1;
}