集合 的交和差的运算与实现.doc

集合 的交和差的运算与实现.doc

ID:55717436

大小:26.00 KB

页数:7页

时间:2020-05-26

集合 的交和差的运算与实现.doc_第1页
集合 的交和差的运算与实现.doc_第2页
集合 的交和差的运算与实现.doc_第3页
集合 的交和差的运算与实现.doc_第4页
集合 的交和差的运算与实现.doc_第5页
资源描述:

《集合 的交和差的运算与实现.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;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;}//差集函

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。