网络152蒋发明吴宏磊郑杨子大大数据处理

上传人:无*** 文档编号:100183243 上传时间:2022-06-02 格式:DOC 页数:102 大小:281.50KB
收藏 版权申诉 举报 下载
网络152蒋发明吴宏磊郑杨子大大数据处理_第1页
第1页 / 共102页
网络152蒋发明吴宏磊郑杨子大大数据处理_第2页
第2页 / 共102页
网络152蒋发明吴宏磊郑杨子大大数据处理_第3页
第3页 / 共102页
资源描述:

《网络152蒋发明吴宏磊郑杨子大大数据处理》由会员分享,可在线阅读,更多相关《网络152蒋发明吴宏磊郑杨子大大数据处理(102页珍藏版)》请在装配图网上搜索。

1、word课程设计报告设计论文题目:大数据处理学院名称:电子与信息工程学院专业班级:网络工程15-2 班成员某某:吴宏磊学号成员某某:子学号成员某某:发明学号指导教师:盛啸涛2016 年 1 月 6 日目录一、概述31、实验容32、实验目的43、组员权重:4二、系统设计41、题目分析:42、数据结构设计43、程序流程图54、详细设计5三、实验结果6四、实验总结61、工作日志62、实验心得63、参考文献7五、附件:程序源码7一、 概述1、 实验容1读取文件中的密码(password)字段,统计密码出现的次数count,写入文件。不需要排序。格式:每行一条记录,password和count中间用TA

2、B分隔即C语言中的t。ReadPassword2读取,对密码出现次数按照降序排序。分别采用:直接插入排序、希尔排序、冒泡排序、快速排序、直接选择排序、堆排序、归并排序、基数排序;求出每种排序方法所需要的绝对时间。屏幕上输出各种各种排序的绝对时间。最后屏幕上输出出现次数最多的20个密码与次数。RankTimePassword3读取,使用链表存放,使用顺序查找,随机生成2000个user_id11,230,000之的,再随机生成20个user_id大于1,230,000的,输出查找所花总时间。SearchTimeNode4读取,按照用户id使用二叉排序树存放,随机生成2000个user_id11,

3、230,000之的,再随机生成20个user_id大于1,230,000的,输出查找所花总时间。SearchTimeTree5读取,先按照user_id排序,结果写入。用不同的排序方法分别输出排序所需时间。如果所花时间过长,请缩小数据围,并估算最终所需的大概时间RankTimeId6读取,使用二分查找,随机生成2000个user_id11,230,000之的,再随机生成20个user_id大于1,230,000的,输出查找所花总时间。只计算查找的时间SearchTimeTwo7设计一个哈希存储的方案,用来存放中的数据关键字为密码;设计20个存在的密码和不存在的密码,输出该密码和出现的次数,以与

4、查找所花总时间。HaxiStore2、 实验目的通过数据结构课程设计,让我们了解8种排序的方法和运算时间,明白了大数据处理的方法,了解了哈希存储的方案以与所需查找的时间,利用二分查找随机产生的数据所需要的时间,通过这次实验,回顾了以前所学习的知识,更加掌握了数据结构的排序和算法。3、 组员权重:发明:吴宏磊:子:二、 系统设计1、 题目分析:要求对大数据进展处理,每行包含一条记录,每条记录包含:user_id和password中间为TAB分隔。2、 数据结构设计3、 程序流程图文字描述:主函数主要为while循环,对应的功能号进入对应的功能,0如此退出循环,每个功能都是根据学期和班级来进入相应

5、的数据文件。4、 详细设计全局变量有int behind,Term t1,t2,behind用于防止输出成绩单时将未录入的学生成绩输出在程序中定义了三个类:Term,Cls,Stu,运用到了类的嵌套,学生嵌套在班级中,班级嵌套在学期里,学生类中有许多函数用于实现某些功能。在程序中还有readfile读文件函数和writetofile写文件函数,读文件函数设置为inline函数加快程序运行效率。主函数主要为一个while循环,输入相应的功能号进入相应的函数功能模块,输入0为完毕,在各个功能模块开始前都会进展一次读文件操作,进展处理后将修改或者录入的数据重新写入到文件中覆盖原有数据。读写文件用到了

6、fstream,istream和ostream。文件为txt文件格式为用于保存第一学期1班的成绩数据。三、 实验结果四、 实验总结1、 工作日志日期时间容完成模块122613:30-16:30整个程序的规划完成文件的写入12. 2713:30-16:30了解前四个算法完成前四个排序12. 2813:30-16:30了解后四个算法完成后四个排序12. 2913:30-16:30了解链表存放完成链表存放12. 3013:30-16:30了解二分查找完成二分查找1. 0313:30-16:30了解哈希存储完成哈希存储1. 0413:30-16:30辩论程序的测试2、 实验心得本次课程设计我们所设计的

7、程序是大数据处理,在做本次设计前我们便对整体程序所需要的功能进展分类,按功能模块对程序功能进展实现,这让我们学到了在完成一个较大的程序时应该先进展策划,将大功能分解成一个个小功能,然后将小功能进展实现,最后整体整合寻找bug,进展修复。另外我们还稍微了解了文件流的运用,以与用到了一些文件操作,写入和读出;我们还运用了类的嵌套,对数据进展更好的分类。在完成这次课程设计中也遇到了一些问题:对文件操作不够熟练,对文件流得概念不怎么了解,在进展编程时对程序结构设计的不够好,所以在寻找bug的时候太费劲,在调试程序是整体思路不够清晰,所以也浪费了大量时间,在编程中一些根本的语法也不够熟练,需要经常性的查

8、阅书籍和上网。当然,本次课程设计还是非常有益的,这锻炼了我们组员的团队合作能力,让我们了解,一个软件是需要许多人一起来完成,一起找bug,一起修复,也让我们认识到自己在编程方面的不足和需要改良的一些地方。3、 参考文献C+文件读写详解ofstream,ifstream,fstream:c+读写文件流C+学习笔记之对文件的操作blog.163./foginwind126/blog/static/3545433/五、 附件:程序源码#include#include#include#include#includeusing namespace std;class Userpublic:User()u

9、ser_id=0;password=;count=0;int user_id;string password;int count;User();typedef struct UserNodeUserNode()userNode_id=0;passwordNode=;countNode=0;nextNode=NULL;int userNode_id;string passwordNode;int countNode;struct UserNode *nextNode;UserNode;typedef struct nodenode()next=NULL;char data4;struct nod

10、e *next;string passw; RecType1;typedef struct nodeIdnodeId()next=NULL;char data7;struct nodeId *next;string passw; RecType1Id;struct UserTreeUserTree()lchild=NULL;rchild=NULL;data=0;passw=;struct UserTree *lchild,*rchild;int data;string passw;#define IdNum 25000int fcount=0;/用于遍历用户User uIdNum;/所有用户U

11、serNode unIdNum;string passwIdNum;/用于存放重复的密码int pw=0;/用于确定放到passw数组中的序号int status=0;/用于确定是否重复/快速排序void QuickSort(User u,int s,int t)int i=s,j=t;int temp;string temp1;if(si & uj.count=temp)/从右向左,找第1个小于temp的uj j-;ui.count=uj.count;/ui和uj 交换 ui.password=uj.password;while(i=temp)/从左向右,找第1个大于temp的uji+; u

12、j.count=ui.count;/ui和uj 交换 uj.password=ui.password;ui.count=temp;ui.password=temp1;QuickSort(u,s,i-1);/左区间递归QuickSort(u,i+1,t);/右区间递归void QuickSortId(User u,int s,int t)int i=s,j=t;int temp;string temp1;if(si & uj.user_id=temp)/从右向左,找第1个小于temp的uj j-;ui.user_id=uj.user_id;/ui和uj 交换 ui.password=uj.pas

13、sword;while(i=temp)/从左向右,找第1个大于temp的uji+; uj.user_id=ui.user_id;/ui和uj 交换 uj.password=ui.password;ui.user_id=temp;ui.password=temp1;QuickSortId(u,s,i-1);/左区间递归QuickSortId(u,i+1,t);/右区间递归/堆排序,建立堆void sift(User r,int low,int high)int i=low,j=2*i;/j为i的左子树int temp=ri.count;string temp1;temp1=ri.password

14、;while(j=high)if(jhigh & rj.countrj+1.count) j+;/假设右子树大,如此把j指向右子树if(temprj.count)ri.count=rj.count;/将rj放到根节点上ri.password=rj.password;i=j;/修改i和j,以向下筛选j=2*i;else break; ri.count=temp;/被筛选节点放入最后位置,即最大或最小值ri.password=temp1; void siftId(User r,int low,int high)int i=low,j=2*i;/j为i的左子树int temp=ri.user_id;

15、string temp1;temp1=ri.password;while(j=high)if(jhigh & rj.user_idrj+1.user_id) j+;/假设右子树大,如此把j指向右子树if(temprj.user_id)ri.user_id=rj.user_id;/将rj放到根节点上ri.password=rj.password;i=j;/修改i和j,以向下筛选j=2*i;else break; ri.user_id=temp;/被筛选节点放入最后位置,即最大或最小值ri.password=temp1; /归并排序void Merge(User R,int low,int mid

16、,int high,int n)User *R1IdNum;int i=low,j=mid+1,k=0; /k是E1的下标,i、j分别为第1、2段的下标for(int h=0;h=high;h+)R1h=new User;/动态分配空间while(i=mid & j=high)/在第1段和第2段均未扫描完时循环 if(Ri.countcount=Rj.count;R1k-password=Rj.password;j+;k+;else/将第1段中的元素放入R1中 R1k-count=Ri.count;R1k-password=Ri.password;i+;k+;while(icount=Ri.c

17、ount;R1k-password=Ri.password;i+;k+;while(jcount=Rj.count;R1k-password=Rj.password;j+;k+;for(k=0,i=low;icount;Ri.password=R1k-password;void MergePass(User R,int length,int n)int i;for(i=0;i+2*length-1n;i=i+2*length)Merge(R,i,i+length-1,i+2*length-1,n);if(i+length-1n) Merge(R,i,i+length-1,n-1,n);void

18、 MergeSort(User R,int n)int length;for(length=1;lengthn;length=2*length)MergePass(R,length,n);void MergeId(User R,int low,int mid,int high,int n)User *R1IdNum;int i=low,j=mid+1,k=0; /k是E1的下标,i、j分别为第1、2段的下标for(int h=0;h=high;h+)R1h=new User;/动态分配空间while(i=mid & j=high)/在第1段和第2段均未扫描完时循环 if(Ri.user_idu

19、ser_id=Rj.user_id;R1k-password=Rj.password;j+;k+;else/将第1段中的元素放入R1中 R1k-user_id=Ri.user_id;R1k-password=Ri.password;i+;k+;while(iuser_id=Ri.user_id;R1k-password=Ri.password;i+;k+;while(juser_id=Rj.user_id;R1k-password=Rj.password;j+;k+;for(k=0,i=low;iuser_id;Ri.password=R1k-password;void MergePassId

20、(User R,int length,int n)int i;for(i=0;i+2*length-1n;i=i+2*length)MergeId(R,i,i+length-1,i+2*length-1,n);if(i+length-1n) MergeId(R,i,i+length-1,n-1,n);void MergeSortId(User R,int n)int length;for(length=1;lengthn;length=2*length)MergePassId(R,length,n);/基数排序void RadixSort(RecType1 *&p,int r,int d)/p

21、为待排序序列链表指针,r为基数,d为关键字位数 RecType1 *head10,*tail10,*t;/定义各链队的首尾指针 int i,j,k;for (i=0;i=d-1;i+) /从低位到高位循环 for (j=0;jdata);if(i=0)if(tempdataitemp-0; /找第k个链队else if(temp9 & tempdataitemp-0; /找第k个链队else if(temp99 & tempdataitemp-0; /找第k个链队else if(temp999)itemp=3;k=p-dataitemp-0; /找第k个链队else if(i=1)if(tem

22、p9 & tempdataitemp-0; /找第k个链队else if(temp99 & tempdataitemp-0; /找第k个链队else if(temp999)itemp=2;k=p-dataitemp-0; /找第k个链队else if(i=2)if(temp9 & temp99 & tempdataitemp-0; /找第k个链队else if(temp999)itemp=1;k=p-dataitemp-0; /找第k个链队else if(i=3)if(temp9 & temp99 & temp999)itemp=0;k=p-dataitemp-0; /找第k个链队if(hea

23、dk=NULL) /进展分配,即采用尾插法建立单链表 ,第k个链队空时,对头队尾均指向*p headk=p; tailk=p; elsetailk-next=p; tailk=p;p=p-next; /取下一个待排序的元素p=NULL;/重新用p来收集所有节点 for (j=0;jnext=headj;t=tailj;t-next=NULL; /最后一个结点的next域置NULL void RadixSortId(RecType1Id *&p,int r,int d)/p为待排序序列链表指针,r为基数,d为关键字位数 RecType1Id *head10,*tail10,*t;/定义各链队的首

24、尾指针 int i,j,k;for (i=0;i=d-1;i+) /从低位到高位循环 for (j=0;jdata);if(i=0)if(tempdataitemp-0; /找第k个链队else if(temp9 & tempdataitemp-0; /找第k个链队else if(temp99 & tempdataitemp-0; /找第k个链队else if(temp999 & tempdataitemp-0; /找第k个链队else if(temp9999 & tempdataitemp-0; /找第k个链队else if(temp99999 & tempdataitemp-0; /找第k

25、个链队else if(temp999999 & tempdataitemp-0; /找第k个链队else if(i=1)if(temp9 & tempdataitemp-0; /找第k个链队else if(temp99 & tempdataitemp-0; /找第k个链队else if(temp999 & tempdataitemp-0; /找第k个链队else if(temp9999 & tempdataitemp-0; /找第k个链队else if(temp99999 & tempdataitemp-0; /找第k个链队else if(temp999999 & tempdataitemp-

26、0; /找第k个链队else if(i=2)if(temp9 & temp99 & tempdataitemp-0; /找第k个链队else if(temp999 & tempdataitemp-0; /找第k个链队else if(temp9999 & tempdataitemp-0; /找第k个链队else if(temp99999 & tempdataitemp-0; /找第k个链队else if(temp999999 & tempdataitemp-0; /找第k个链队else if(i=3)if(temp9 & temp99 & temp999 & tempdataitemp-0; /

27、找第k个链队else if(temp9999 & tempdataitemp-0; /找第k个链队else if(temp99999 & tempdataitemp-0; /找第k个链队else if(temp999999 & tempdataitemp-0; /找第k个链队else if(i=4)if(temp9 & temp99 & temp999 & temp9999 & tempdataitemp-0; /找第k个链队else if(temp99999 & tempdataitemp-0; /找第k个链队else if(temp999999 & tempdataitemp-0; /找第

28、k个链队else if(i=5)if(temp9 & temp99 & temp999 & temp9999 & temp99999 & tempdataitemp-0; /找第k个链队else if(temp999999 & tempdataitemp-0; /找第k个链队else if(i=6)if(temp9 & temp99 & temp999 & temp9999 & temp99999 & temp999999 & tempdataitemp-0; /找第k个链队if(headk=NULL) /进展分配,即采用尾插法建立单链表 ,第k个链队空时,对头队尾均指向*p headk=p;

29、 tailk=p; elsetailk-next=p; tailk=p;p=p-next; /取下一个待排序的元素p=NULL;/重新用p来收集所有节点 for (j=0;jnext=headj;t=tailj;t-next=NULL; /最后一个结点的next域置NULL /*读取文件中密码,统计密码出现次数,写入文件password.txt */void ReadPassword()/*读取文件*/ifstream icin;icin.open(user.txt );fcount=0;int a;string b;while(!icin.eof()icinab;ufcount.user_i

30、d=a;ufcount.password=b;fcount+;ufcount.user_id=-1;/将最后一个id设置为-1用于判断是否到最后一个用户icin.close();fcount=0;int fcount2=0;/判断重复次数中的遍历序号int count=0;/重复次数int j=0;/循环变量/*统计次数*/ofstream ocout;ocout.open(password.txt,ios:ate);while(1)if(ufcount.user_id=-1) break;/*看是否是重复的密码,是重复密码不用再统计*/for(j=0;j=IdNum-1;j+)if(pass

31、wj=) break;if(passwj=ufcount.password)status=1;break;if(status=1) /重复密码fcount+;fcount2=0;count=0;status=0;continue;passwpw=ufcount.password;/将重复密码放到passw数组中/*确定重复次数*/while(1)if(ufcount2.user_id=-1) break;if(ufcount2.password=ufcount.password)count+;fcount2+;ocoutufcount.passwordtcountendl;/写入文件fcoun

32、t+;fcount2=0;count=0;pw+;status=0;ocout.close();/*读取password.txt,对密码出现次数按照降序排序*/void RankTimePassword()int choose=0;cout请输入使用的排序方法:endl;cout 1直接插入排序 2希尔排序 3冒泡排序 4快速排序endl;cout 5直接选择排序 6堆排序 7归并排序 8基数排序 choose;while(1)if(choose=-1)/退出break;/*直接插入排序*/else if(choose=1)/*读取文件*/ifstream icin;icin.open(pas

33、sword.txt );fcount=0;string a;int b;while(!icin.eof()icinab;ufcount.password=a;ufcount.count=b;fcount+;ufcount.count=-1;/将最后一个id设置为-1用于判断是否到最后一个用户icin.close();time_t nowtime,nexttime;/用于统计时间nowtime=time(NULL);/获取当前时间/*直接插入排序*/int temp;int i,j;string temp1;for(int j=1;j=10;j+)for(i=1;i=0 & tempuj.cou

34、nt)uj+1.count=uj.count;uj+1.password=uj.password;j-;uj+1.count=temp;uj+1.password=temp1;nexttime=time(NULL);/获取排好序后的时间ofstream ocout;ocout.open(password1.txt,ios:ate);fcount=0;while(1)if(ufcount.count=-1)break; ocoutufcount.passwordtufcount.countendl;/写入文件fcount+;cout直接插入法所用时间为:(s)-(nexttime-nowtime

35、)/10endl;/*倍数是为了方便显示时间cout出现次数最多的20个密码是:endl;for(int k=0;k=19;k+)/输出出现次数最多的20个密码coutuk.passwordtuk.countchoose;/*/*希尔排序*/else if(choose=2)/*读取文件*/ifstream icin;icin.open(password.txt );fcount=0;string a;int b;while(!icin.eof()icinab;ufcount.password=a;ufcount.count=b;fcount+;ufcount.count=-1;/将最后一个i

36、d设置为-1用于判断是否到最后一个用户icin.close();time_t nowtime,nexttime;/用于统计时间nowtime=time(NULL);/获取当前时间/*希尔排序*/int i,j,gap;int temp;string temp1;gap=(fcount)/2;/增量置初值,fcount也即总的用户个数;for(int k=1;k=100000;k+)/为了延长计算时间方便显示for(int h=1;h0)for(i=gap;i=0 & tempuj.count)/对相隔gap位置的元素组进展排序 uj+gap.count=uj.count;uj+gap.password=uj.password;j=j-gap;uj+gap.count=temp;uj+gap.password=temp1;gap=gap/2;/减小增量 nexttime=time(NULL);/获取排好序后的时间ofstream ocout;ocout.open(password1.txt,ios:ate);fcount=0;while(1)if(ufcount.count=-1)break; ocout

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!