欢迎来到天天文库
浏览记录
ID:55717436
大小:26.00 KB
页数:7页
时间:2020-05-26
《集合 的交和差的运算与实现.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include#include#include//顺序表定义#defineTRUE1#defineFALSE0#defineOK1#defineERROR0#defineOVERFLOW-2#defineIN_THIS_LIST1#defineNOT_IN_THIS_LIST0//宏定义typedefcharElemtype;typedef
2、intStatus;typedefstructList{Elemtypedata;structList*next;}LNode,*LinkList;//结构体定义StatusInitList(LinkList&L){L=(LinkList)malloc(sizeof(LNode));if(!L)exit(OVERFLOW);L->data=NULL;L->next=NULL;returnOK;}//构造表头StatusPrintList(LinkListL){LinkListPrintList=L->nex
3、t;if(!L->next){cout<<"该集合为空!"<next){cout<data<<",";PrintList=PrintList->next;}cout<data;cout<4、5、(int)e>122)returnERROR;Lin6、kListcompare=(LinkList)malloc(sizeof(LNode));LinkListinsertdata=(LinkList)malloc(sizeof(LNode));compare=L;while(compare->next){if(e==compare->next->data)returnTRUE;elseif(e<(compare->next->data)){insertdata->next=compare->next;insertdata->data=e;compare->n7、ext=insertdata;returnOK;}compare=compare->next;}insertdata->data=e;compare->next=insertdata;insertdata->next=NULL;returnOK;}//向表中增加元素StatusDeleteList_data(LinkList&L,Elemtypee){LinkListDeletedata=L->next;while(Deletedata->next){if(!(Deletedata->next->next)8、&&(Deletedata->next->data==e)){Deletedata->next=NULL;returnOK;}if(Deletedata->next->data==e){Deletedata->next=Deletedata->next->next;returnOK;}Deletedata=Deletedata->next;}Deletedata=L->next;if(Deletedata->data==e){L->next=Deletedata->next;returnOK;}return9、ERROR;}Statusjiaoji(LinkListLa,LinkListLb,LinkList&L){LinkListPa=La->next;LinkListPb=Lb->next;while(Pa){while(Pb){if(Pb->data==Pa->data)InsertList(L,Pa->data);Pb=Pb->next;}Pb=Lb->next;Pa=Pa->next;}returnOK;}//求交集函数Statuschaji(LinkListLa,LinkListLb,LinkList10、&L){Statuscompare=0;LinkListPa,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;}returnOK;}//差集函
4、
5、(int)e>122)returnERROR;Lin
6、kListcompare=(LinkList)malloc(sizeof(LNode));LinkListinsertdata=(LinkList)malloc(sizeof(LNode));compare=L;while(compare->next){if(e==compare->next->data)returnTRUE;elseif(e<(compare->next->data)){insertdata->next=compare->next;insertdata->data=e;compare->n
7、ext=insertdata;returnOK;}compare=compare->next;}insertdata->data=e;compare->next=insertdata;insertdata->next=NULL;returnOK;}//向表中增加元素StatusDeleteList_data(LinkList&L,Elemtypee){LinkListDeletedata=L->next;while(Deletedata->next){if(!(Deletedata->next->next)
8、&&(Deletedata->next->data==e)){Deletedata->next=NULL;returnOK;}if(Deletedata->next->data==e){Deletedata->next=Deletedata->next->next;returnOK;}Deletedata=Deletedata->next;}Deletedata=L->next;if(Deletedata->data==e){L->next=Deletedata->next;returnOK;}return
9、ERROR;}Statusjiaoji(LinkListLa,LinkListLb,LinkList&L){LinkListPa=La->next;LinkListPb=Lb->next;while(Pa){while(Pb){if(Pb->data==Pa->data)InsertList(L,Pa->data);Pb=Pb->next;}Pb=Lb->next;Pa=Pa->next;}returnOK;}//求交集函数Statuschaji(LinkListLa,LinkListLb,LinkList
10、&L){Statuscompare=0;LinkListPa,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;}returnOK;}//差集函
此文档下载收益归作者所有