C++单链表实现集合并交差 葬蓝色&&洋洋得意

上传人:飞*** 文档编号:39936310 上传时间:2018-05-21 格式:DOCX 页数:7 大小:21.73KB
返回 下载 相关 举报
C++单链表实现集合并交差 葬蓝色&&洋洋得意_第1页
第1页 / 共7页
C++单链表实现集合并交差 葬蓝色&&洋洋得意_第2页
第2页 / 共7页
C++单链表实现集合并交差 葬蓝色&&洋洋得意_第3页
第3页 / 共7页
C++单链表实现集合并交差 葬蓝色&&洋洋得意_第4页
第4页 / 共7页
C++单链表实现集合并交差 葬蓝色&&洋洋得意_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《C++单链表实现集合并交差 葬蓝色&&洋洋得意》由会员分享,可在线阅读,更多相关《C++单链表实现集合并交差 葬蓝色&&洋洋得意(7页珍藏版)》请在金锄头文库上搜索。

1、/ node.h: interface for the node class. / /#if !defined(AFX_NODE_H_13AAF586_EC6E_4ED8_9F63_39EB38059F31_INCLUDED_) #define AFX_NODE_H_13AAF586_EC6E_4ED8_9F63_39EB38059F31_INCLUDED_ #include using namespace std; #if _MSC_VER 1000 #pragma once #endif / _MSC_VER 1000 class SetOperations; class node pri

2、vate: int data; node * next; public: friend class SetOperations; node(int d); node(); virtual node();#endif / !defined(AFX_NODE_H_13AAF586_EC6E_4ED8_9F63_39EB38059F31_INCLUDED_)/ node.cpp: implementation of the node class. / /#include “node.h“/ / Construction/Destruction /node:node() next=NULL; node

3、:node() node:node(int d) data=d; next=NULL; / SetOperations.h: interface for the SetOperations class. / /#if !defined(AFX_SETOPERATIONS_H_A7D6B068_54BD_4FE3_9985_326D688DCD50_INCLUDED_) #define AFX_SETOPERATIONS_H_A7D6B068_54BD_4FE3_9985_326D688DCD50_INCLUDED_ #include using namespace std; #if _MSC_

4、VER 1000 #pragma once #endif / _MSC_VER 1000 #include “node.h“ class SetOperations public: void SetOperations_BDifferenceA(); void SetOperations_ADifferenceB(); void SetOperations_UnionAndIntersection(); void SetOperations_Out(int key); bool SetOperations_Create_B(); bool SetOperations_Create_A(); S

5、etOperations(); virtual SetOperations();private: node S6; ;#endif / !defined(AFX_SETOPERATIONS_H_A7D6B068_54BD_4FE3_9985_326D688DCD50_INCLUDED_)/ SetOperations.cpp: implementation of the SetOperations class. / /#include “SetOperations.h“/ / Construction/Destruction /SetOperations:SetOperations() Set

6、Operations:SetOperations()bool SetOperations:SetOperations_Create_A() node *p; node *q; int x; char ch; cout9|chx; p=S+0; for(;p-next;) if(p-next-datax) break; if(p-next-data=x) p=S+0; p=p-next; S0.next=NULL; for(;p;) q=p; p=p-next; delete q; fflush(stdin); return false; p=p-next; q=new node(x); q-n

7、ext=p-next; p-next=q; cout9|chx; p=S+1; for(;p-next;) if(p-next-datax) break; if(p-next-data=x) p=S+1; p=p-next; S1.next=NULL; for(;p;) q=p; p=p-next; delete q; fflush(stdin); return false; p=p-next; q=new node(x); q-next=p-next; p-next=q; coutnext;) coutnext-datanext; coutnext;) p=new node(r-next-d

8、ata); p-next=q-next; q-next=p; q=q-next; r=r-next; r=S+1; o=S+3; for(;r-next;) p=S+2; for(;p-next;) if(p-next-datar-next-data) q=new node(r-next-data); q-next=p-next; p-next=q; break; if(p-next-data=r-next-data) q=new node(r-next-data); q-next=o-next; o-next=q; o=o-next; break; p=p-next; if(p-next=N

9、ULL) q=new node(r-next-data); q-next=p-next; p-next=q; r=r-next; void SetOperations:SetOperations_ADifferenceB() node *p; node *q; node *r; node *o; p=S+0; r=S+4; for(;p-next;) q=S+3; for(;q-next;) if(q-next-datap-next-data) o=new node(p-next-data); o-next=r-next; r-next=o; r=r-next; break; if(q-nex

10、t-data=p-next-data) break; q=q-next; if(q-next=NULL) o=new node(p-next-data); o-next=r-next; r-next=o; r=r-next; p=p-next; void SetOperations:SetOperations_BDifferenceA() node *p; node *q; node *r; node *o; p=S+1; r=S+5; for(;p-next;) q=S+3; for(;q-next;) if(q-next-datap-next-data) o=new node(p-next

11、-data); o-next=r-next;r-next=o; r=r-next; break; if(q-next-data=p-next-data) break; q=q-next; if(q-next=NULL) o=new node(p-next-data); o-next=r-next; r-next=o; r=r-next; p=p-next; #include “SetOperations.h“ #include using namespace std; int main() SetOperations T; for(;!T.SetOperations_Create_A();)

12、cout“集合A中存在重复元素建立失败!“endl; for(;!T.SetOperations_Create_B();) cout“集合B中存在重复元素建立失败!“endl; T.SetOperations_UnionAndIntersection(); T.SetOperations_ADifferenceB(); T.SetOperations_BDifferenceA(); coutendl; cout“结合A升序排列:“endl; T.SetOperations_Out(0); cout“结合B升序排列:“endl; T.SetOperations_Out(1); cout“结合A并B:“endl; T.SetOperations_Out(2); cout“结合A交B:“endl; T.SetOperations_Out(3); cout“结合A差B:“endl; T.SetOperations_Out(4); cout“结合B差A:“endl; T.SetOperations_Out(5); system(“pause“); return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 研究报告 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号