实现两个递增链表(集合)的并集,交集和差集。请牛人帮忙。
LinkList *Union(LinkList *D,LinkList *H,LinkList *L){
LinkList *pd,*ph,*pl;
L=(LinkList *)malloc(sizeof(LinkList));
pl=L->next;
pd=D->next;
ph=H->next;
while(pd&&ph)
{
if(pd->data<ph->data)
{
pl->next=pd;
pd=pd->next;
pl=pl->next;
}
if(pd->data=ph->data)
{
pl->next=pd;
pd=pd->next;
ph=ph->next;
pl=pl->next;
}
else
{
pl->next=ph;
ph=ph->next;
pl=pl->next;
}
}
while(pd!=NULL)
pl->next=pd;
while(ph!=NULL)
pl->next=ph;
}
LinkList *Inter(LinkList *D,LinkList *H,LinkList *L)
{
LinkList *pl,*pd,ph;
L=(LinkList *)malloc(sizeof(LinkList));
pd=D->next;
ph=H->next;
pl=L->next;
while(pd!=NULL)
{
while(ph!=NULL)
{
if(pd->data==ph->data)
{
pl->next=pd;
pd=pd->next;
ph=ph->next;
pl=pl->next;
}
else
ph=ph->next;
}
pd=pd->next;
}
}
LinkList *Differ(LinkList *D,LinkList *H,LinkList *L)
{
LinkList *pl,*pd,*ph;
int i=0
L=(LinkList *)malloc(sizeof(LinkList));
pd=D->next;
ph=H->next;
pl=L->next;
while(pd!=NULL)
{
while(ph!=NULL)
{
if(pd->data==ph->data)
{
pd=pd->next;
ph=ph->next;
i++;
}
else
ph=ph->next;
}
if(i=0)
{
pl->next=pd;
pl=pl->next;
pd=pd->next;
}
pd=pd->next;
}
}