1、include
2、Elemtype; typedef int Status; typedef struct List { Elemtype data; struct List *next; }LNode,*LinkList; //结构体定义 Status InitList(LinkList &L) { L=(LinkList)malloc(sizeof(LNode)); if(!L) exit(OVERFLOW); L->data=NULL;L->next=NULL; return OK; } //构造表头 Sta
3、tus PrintList(LinkList L)
{
LinkList PrintList=L->next;
if(!L->next) {cout<<"该集合为空!"< 4、nsertList(LinkList &L,Elemtype e)
{
if((int)e<97||(int)e>122) return ERROR;
LinkList compare=(LinkList)malloc(sizeof(LNode));
LinkList insertdata=(LinkList)malloc(sizeof(LNode));
compare=L;
while(compare->next)
{
if(e==compare->next->data) return TRUE;
else if(e<(compare-> 5、next->data))
{
insertdata->next=compare->next;
insertdata->data=e;
compare->next=insertdata;
return OK;
}
compare=compare->next;
}
insertdata->data=e;
compare->next=insertdata;
insertdata->next=NULL;
return OK;
} // 6、向表中增加元素
Status DeleteList_data(LinkList &L,Elemtype e)
{
LinkList Deletedata=L->next;
while(Deletedata->next)
{
if(!(Deletedata->next->next)&&(Deletedata->next->data==e))
{Deletedata->next=NULL; return OK;}
if(Deletedata->next->data==e)
{
Deletedata->next=Del 7、etedata->next->next;
return OK;
}
Deletedata=Deletedata->next;
}
Deletedata=L->next;
if(Deletedata->data==e)
{
L->next=Deletedata->next;
return OK;
}
return ERROR;
}
Status jiaoji(LinkList La,LinkList Lb,LinkList &L)
{
LinkList Pa=La->next;
LinkList Pb= 8、Lb->next;
while(Pa)
{
while(Pb)
{
if(Pb->data==Pa->data)
InsertList(L,Pa->data);
Pb=Pb->next;
}
Pb=Lb->next;
Pa=Pa->next;
}
return OK;
} //求交集函数
Status chaji(LinkList La, LinkList Lb,LinkList &L)
{
Status c 9、ompare=0;
LinkList Pa,Pb;
Pa=La->next;
Pb=Lb->next;
while(Pa)
{
while(Pb)
{
if(Pa->data==Pb->data) compare++;
Pb=Pb->next;
}
if(!compare) InsertList(L,Pa->data);
compare=0;
Pb=Lb->next;
Pa=Pa->next;
}
return OK;
} / 10、/差集函数
Status bingji(LinkList La,LinkList Lb,LinkList &L)
{
LinkList Pa=La->next;
LinkList Pb=Lb->next;
while(Pa){
InsertList(L,Pa->data); Pa=Pa->next;}
while(Pb){
InsertList(L,Pb->data); Pb=Pb->next;}
return OK;
} //并集函数
Status buji(LinkList L,LinkLi 11、st &List)
{
Status set=97;
while(set<=122)
{
InsertList(List,(Elemtype)set);
set++;
}
LinkList PL=L->next;
LinkList P=List->next;
while(PL)
{
while(P)
{
if(P->data==PL->data)
DeleteList_data(List,P->data);
P=P->next;
}
P=List->next;
12、 PL=PL->next;
}
return OK;
} //补集函数
Status compare(LinkList L,Elemtype e)
{
LinkList P=L->next;
while(P)
{
if(P->data==e) return IN_THIS_LIST;
P=P->next;
}
return NOT_IN_THIS_LIST;
} //判定函数
Status ziji(LinkList La,LinkList Lb)
{
L 13、inkList Pb=Lb->next;
while(Pb)
{
if(!compare(La,Pb->data)) return FALSE;
Pb=Pb->next;
}
return TRUE;
}
Status menu(LinkList A,LinkList B)
{
int i;
do{
system("cls");
cout<<" * * * * * * 集合的计算 * * * * *\n";
cout<<" 14、 * <1>:输入集合信息 *\n";
cout<<" * <2>:输出交集信息 *\n";
cout<<" * <3>:输出差集信息 *\n";
cout<<" * <4>:输出并集信息 *\n";
cout<<" * <5>:判定是否子集 *\n";
cout<< 15、" * <6>:输出补集信息 *\n";
cout<<" * <0>:退出管理系统 *\n";
cout<<" * * * * * * * 程尧 制作 * * * * * * *\n";
cout<<"请选择操作(1-6):";
cin>>i;
if(A->next&&B->next) {cout<<"集合A:"; PrintList(A); cout<<"集合B:"; PrintList(B);}
}while 16、i<0||i>6);
return i;
}
int main()
{
LinkList A; InitList(A);
LinkList B; InitList(B);
LinkList J; InitList(J);
LinkList K; InitList(K);
LinkList L; InitList(L);
LinkList M; InitList(M);
Elemtype a;
do{
switch(menu(A,B))
{
case 1:cout<<"请输入集合元素,以“0”结束"<< 17、endl;
cout<<"输入集合A:";
cin>>a;
while(a!='0')
{
InsertList(A,a);
cin>>a;
}
cout<<"输入集合B:";
cin>>a;
while(a!='0')
{
InsertList(B,a);
cin>>a;
}
break;
case 2: jiaoji(A,B,J);
cout<<"两集合的交集:";
PrintList(J);
cout< 18、<"输入任意键返回主菜单"< 19、if(ziji(A,B)) {
cout<<"集合B是集合A的子集"<






