LinkList Intersection(LinkList a, LinkList b)
{
LinkList LA, LB,q;
LA =(LinkList)malloc(sizeof(LNode));
LB = LA;
while (a!=NULL)
{
q=b;
while (q!=NULL)
{
if (q->data == a->data)
{
LB=LB->next=(LinkList)malloc(sizeof(LNode));
LB->data = a->data;
break;
}
q = q->next;
}
a = a->next;
}
LB->next=NULL;
LinkList p;
p = LA;
LA = LA->next;
free(p);
return LA;
}
LinkList Unionset(LinkList a, LinkList b)
{
LinkList L,q;
L=b;
while (a!=NULL)
{
while (b)
{
q=b;
if(a->data==b->data)
break;
b=b->next;
}
if(b==NULL)
{
q=q->next=(LinkList)malloc(sizeof(LNode));
q->data=a->data;
q->next=NULL;
}
b=L;
a=a->next;
}
return L;
}
return LA
return L
都是返回链表的表头。