ImageVerifierCode 换一换
格式:DOCX , 页数:24 ,大小:185.59KB ,
资源ID:1119178      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/1119178.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据结构课程设计报告集合的交并差运算.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

数据结构课程设计报告集合的交并差运算.docx

1、数据结构课程设计报告集合的交并差运算 淮 阴 工 学 院数据结构课程设计报告作 者:学 号:班 级:学 院:专 业:题 目:指导教师: 2016年1月1 课题描述编制一个能演示执行集合的交、并和差运算的程序。集合元素用小写英文字母,执行各种操作应以对话方式执行。利用单链表表示集合;理解好三种运算的含义2 系统设计2.1功能模块设计2.1.1基于单链表设计(1)节点结构单元模块定义有序表的节点结构;typedef struct LNode/定义结构体类型指针 char data; struct LNode*next;*pointer;(2)有序表单元模块实现有序表的抽象数据类型;readdata

2、(pointer head)初始条件:head是以head为头节点的空链表。操作结果:生成以head为头节点的非空链表。pop(pointer head)初始条件:head是以head为头节点的非空链表。操作结果:将以head为头节点的链表中数据逐个输出。(3)集合单元模块实现集合获得抽象数据类型;and(pointer head1,pointer head2,pointer head3)初始条件:链表head1、head2、head3已存在操作结果:生成一个由head1和head2的并集构成的集合head3。or(pointer head1,pointer head2,pointer hea

3、d3)初始条件:链表head1、head2、head3已存在操作结果:生成一个由head1和head2的交集构成的集合head3。(4)主程序模块Void main()初始化;do接受命令;处理命令;while(“命令”!=“退出”);2.1.2基于顺序表设计(1)顺序表结构单元模块定义顺序表的结构体;typedef struct /定义SeqList的结构体 DataType listMaxSize; int size ; SeqList;(2)函数单元模块定义各种所需函数;int ListDel( SeqList *L , int i , DataType *x)/顺序表的删除函数int

4、ListGet(SeqList L , int i , DataType *x)/获取顺序表的元素函数void ListFind(SeqList L , DataType x)/顺序表查找元素函数void SelcetSort(SeqList *L ) /顺序表选择排序函数void UnionSet(SeqList mylist1 , SeqList mylist2)/求并集函数void MixedSet(SeqList mylist1 , SeqList mylist2)/求交集元素函数void DiffentSet(SeqList mylist1 , SeqList mylist2) /求

5、差集元素函数(3)主函数单元模块定义主函数;void main() SeqList mylist1 , mylist2;/定义顺序表mylist int i; DataType temp; ListInitiate( &mylist1); ListInitiate( &mylist2);/初始化两个顺序表2.2数据结构设计2.2.1基于单链表设计定义结构体类型指针,集合采用单链表存储。typedef struct LNode/定义结构体类型指针head1=(pointer)malloc(sizeof(struct LNode); head1-next=NULL; head2=(pointer)

6、malloc(sizeof(struct LNode); head2-next=NULL; head3=(pointer)malloc(sizeof(struct LNode);2.1.2基于顺序表设计typedef struct /定义SeqList的结构体 DataType listMaxSize;int size ;void UnionSet(SeqList mylist1 , SeqList mylist2) /求并集 int m, i,j ; DataType x; SeqList Test ; ListInitiate( &Test); /定义并初始化2.3算法设计2.3.1基于单

7、链表,顺序表设计 图2.1系统模块流程图否 是否 是图2.2主菜单流程图 否 是 否 是 图2.3并集模块流程图求交集与差集的流程图与并集类似。3 详细设计3.1菜单设计(基于单链表)图3.1主界面3.2源代码设计(基于单链表)#include#includetypedef struct LNode/定义结构体类型指针 char data; struct LNode*next;*pointer;void readdata(pointer head)/定义输入集合函数 pointer p; char tmp; scanf(%c,&tmp); while(tmp!=n) p=(pointer)ma

8、lloc(sizeof(struct LNode);/为指针P申请内存空间 p-data=tmp; p-next=head-next; head-next=p; scanf(%c,&tmp); void pop(pointer head)/定义输出集合函数 pop()出栈函数 pointer p; p=head-next; while(p!=NULL) printf(%c,p-data); p=p-next; printf(n);void and(pointer head1,pointer head2,pointer head3)/定义集合的并集函数 pointer p1,p2,p3; p1=

9、head1-next; while(p1!=NULL)/遍历链表head1 p3=(pointer)malloc(sizeof(struct LNode); p3-data=p1-data; p3-next=head3-next; head3-next=p3; p1=p1-next; p2=head2-next; while(p2!=NULL)/遍历链表head2 p1=head1-next; while(p1!=NULL)&(p1-data!=p2-data) p1=p1-next; if (p1=NULL) p3=(pointer)malloc(sizeof(struct LNode);

10、p3-data=p2-data; p3-next=head3-next; head3-next=p3; p2=p2-next; void or(pointer head1,pointer head2,pointer head3)/定义集合的交集函数 pointer p1,p2,p3; p1=head1-next; while(p1!=NULL) p2=head2-next; while(p2!=NULL)&(p2-data!=p1-data) p2=p2-next; if(p2!=NULL)&(p2-data=p1-data) p3=(pointer)malloc(sizeof(struct

11、LNode); p3-data=p1-data; p3-next=head3-next; head3-next=p3; p1=p1-next; void differ(pointer head1,pointer head2,pointer head3)/定义集合的差集函数 pointer p1,p2,p3; p1=head1-next; while(p1!=NULL) p2=head2-next; while(p2!=NULL)&(p2-data!=p1-data) p2=p2-next; if(p2=NULL) p3=(pointer)malloc(sizeof(struct LNode);

12、 p3-data=p1-data; p3-next=head3-next; head3-next=p3; p1=p1-next; void main()/主函数 int x; printf(输入数据,按回车键结束,第一个集合大于第二个集合)n); pointer head1,head2,head3; head1=(pointer)malloc(sizeof(struct LNode); head1-next=NULL; head2=(pointer)malloc(sizeof(struct LNode); head2-next=NULL; head3=(pointer)malloc(sizeo

13、f(struct LNode); head3-next=NULL; printf(请输入集合1:n); readdata(head1);/调用输入集合函数 printf(请输入集合2:n); readdata(head2);/调用输入集合函数A:printf(1.并集 2.交集 3.差集 4.结束 x.重新运算n); do printf(请选择序号n); scanf(%d,&x);switch(x)case 1: printf(两集合的并是n); and(head1,head2,head3);/调用并集函数 pop(head3); head3-next=NULL; break;case 2: printf(两集合的交是n); or(head1,head2,head3);/调用交集函数 pop(head3); head3-next=NULL; break;case 3: printf(两集合的差是n); differ(head1,head2,head3);/调用差集函数 pop(head3); head3-next=NULL; break; case 4:break; default:goto A; while

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1