构造A,B两元素的并(删B表补A表)
void union(List &La, List &Lb)
{
La_len = ListLength(La);
while(!ListEmpty(Lb)){
List(Delete,1,e);
if(!LocateELem(La,e))
ListInsert(La,++La_len,e)
}
Destroy(Lb)
}
非纯集合B化为纯集合A(本质上同上算法一样)
void purge(List &La, List &Lb)
{
InitList(La);
La_len = 0;
while(!ListEmpty(Lb)){
Delete(Lb,1,e);
if(!LocateElem(La,e)ListInsert(La,++La_len,e));
}
DestroyList(Lb);
}
判断A,B两集合相等(构造表List Lc = List Lb, 删相同元素,最后Lc为空则La ,Lb相等)
bool isequal(List La, List Lb){
La_len = ListLength(La);
Lb_len = ListLength(Lb);
if(La_len != Lb_len)
return FALSE;
else{
InitList(Lc);
for(k=1; k<=La_len; k++)
GetElem(La,k,e);
ListInsert(Lc,k,e);
}
found = TRUE;
for(k=1; k<=Lb_len,found; k++){
GetElem(Lb,k,e);
i=(Locate(Lc,e));
if(i==0)
found = FALSE;
else
ListDelete(Lc,i,e);
}
if(found && ListEmpty(Lc))
return TURE;
else
return FALSE;
DestroyList(Lc)
}
}