




已阅读5页,还剩27页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
数据结构数据结构课程设计报告课程设计报告 课程名称课程名称 :赫夫曼编码系统 姓姓 名名 : 学学 号号 : 专专 业业 : 班班 级级 : 指导教师指导教师 : 二二一二年一二年 十二月十二月 1 / 32 目录目录 contents 1.课程小组课程小组 -2 1.1.小组成员及分工-2 2.设计目的和要求设计目的和要求-2 3.需求分析需求分析 -2 4.设计说明设计说明 -2 4.1.文件编码(加密) -2 4.2.文件解码(解密) -3 5.详细设计详细设计 -3 5.1.程序主体结构-3 5.2.主要算法说明-3 5.2.1.huffman树-3 5.2.2.huffman编码-5 5.2.3.字符权重计算-6 5.2.4.字符解码-9 6.实验结果实验结果-10 6.1.实验结果说明 -10 6.2.程序运行截图 -11 7.设计体会设计体会-12 8.参考文献参考文献-13 9.附:程序代码附:程序代码 -13 2 / 32 1. 课程小组课程小组 1.1.小组成员及分工小组成员及分工 2. 设计目的和要求设计目的和要求 通过课程设计,让学生进一步熟悉与巩固数据结构中常用算法,加深体会利用数据结 构的算法解决实际问题的能力,培养学生进行复杂程序设计的技能,提高学生的思维能力、 并促进其综合应用能力、分析能力和团队合作能力的提高。 3. 需求分析需求分析 随着网络信息科技的不断高速发展,网络上的问题也不断显露出来,特别是人们特别 关注的安全隐私问题,所以文件的传输安全性要特别地亟待解决和提高。 本次的课程设计以赫夫曼编码为题,设计出赫夫曼文件编码系统,旨在对文件中的内 容进行分析、统计、处理,进而按照赫夫曼编码的理论,对文件进行简单加密。特别是, 不同的文本文件有不同的字符处理形式,所以因此每一个文本都会有一个相应的密钥,用 于对文本的解码。 4. 设计说明设计说明 本次编写的程序按着对文件的编码(加密)和解码(解密)的两大步骤展开。 4.1.文件编码(加密)文件编码(加密) 首先选择文件编码程序。进入程序后,会要求操作人员选择将要编码的文件,并将其 导入到程序中,程序正确导入文件后将会对文件从开始至结束扫描一遍,对文件中的字符 进行统计,在最后计算出每个字符出现的频率,并将频率换算成每个字符相应的权重。然 后根据得到的字符权重,构造赫夫曼树并因此完成赫夫曼编码(至此,文件的导入分析过 程已完成) 。 然后让操作人员选择对文件进行编码。此时,程序将会继续打开文件,继续扫描一遍, 并在扫描的过程中将扫描到得字符根据刚才编好的赫夫曼编码进行对照,将对应的赫夫曼 编码写入另一个文件(即加密的文件) ,所以,如果用户代开加密的文件即看到里面全是二 进制代码,并不能分析出里面究竟是什么内容。 (至此,加密的文件应经生成) 。 最后,因为每个文件中的内容不同,所以每个文件的赫夫曼编码也不同,而赫夫曼编 3 / 32 码是根据字符的权重生成的,所以每个文件都对应一个字符权重系列(即密钥) ,如果失去 这个密钥,即使对文件进行了加密,也不同解密文件的内容,即文件加密失效,所以在生 成加密文件后,一定要导出文件的字符权重(即密钥) ,以待之后的解码使用。 (至此,文 件的加密工作应经全部完成) 。 4.2.文件解码(解密)文件解码(解密) 文件的解码程序是一步完成的,即要求操作者首先将之前生成的字符权重(即密钥) 导入程序,程序根据获取到得字符权重,调用赫夫曼编码子程序,进行赫夫曼编码。然后 程序会提示操作者将加密后的文件导入程序中,程序会根据在程序中获取到的二进制编码 与赫夫曼编码进行对照识别,显示出对应的字符,因此,文件的解密工作完成。 5. 详细设计详细设计 5.1.程序主体结构程序主体结构 程序主体结构分为文件编码与文件解码两个子程序。 文件编码后分别导出编码后文件与文件密钥。 文件解码需导入编码文件与文件密钥,然后显示文本内容。 5.2.主要算法说明主要算法说明 5.2.1.huffman 树树 /huffmantree list: list 为赫夫曼树. typedef struct char data; /存放字符数据 int weight; /存放字符权重 int parent, lchild, rchild; /分别为根、左子树、右子树 huffmantree; /static info: info 为存放字符权重的数组指针. typedef struct char data; /存放字符数据 int weight; /存放字符权重 static; /int codesize: codesize 为字符种类个数. 4 / 32 void creathuffmantree(huffmantree * int lnode, rnode; int value1, value2; huffmantree *ptr; limit = codesize * 2 - 1;/limit 为赫夫曼树结点个数 if (list = (huffmantree *)malloc(sizeof(huffmantree) * limit) = null) printf(“ 内存不足, 操作失败!n“); exit(0); /*初始化赫夫曼树各结点信息*/ for(i=0, ptr=list; idata = infoi.data; ptr-weight = infoi.weight; ptr-parent = ptr-lchild = ptr-rchild = -1; for(; idata = 0; ptr-weight = 0; ptr-parent = ptr-lchild = ptr-rchild = -1; /*开始建立赫夫曼树*/ for(i=codesize; idata = ch; ptr-number = 1; ptr-next = characterlist.next; characterlist.next = ptr; +typenumber; else while (current != null) current = current-next; if (current != null) +(current-number); +characternumber; else if (ptr = (data *)malloc(sizeof(data) = null) printf(“ 内存不足, 操作失败!n“); exit(0); ptr-data = ch; ptr-number = 1; ptr-next = current; previous-next = ptr; +typenumber; +characternumber; fclose(fp); codesize = typenumber; info = (static *)malloc(sizeof(static) * codesize); 9 / 32 current = characterlist.next; /将统计好的字符权重信息存入权重文件中 for (int i=0; idata; infoi.weight = (int)(current-number * 100.0 / characternumber); current = current-next; 5.2.4.字符解码字符解码 /此代码用于比较查找赫夫曼编码 bool comparedata(char *tempcode, int position #include #include #include /赫夫曼树结构 typedef struct char data; int weight; int parent, lchild, rchild; huffmantree; /字符权重结构 typedef struct char data; int weight; static; /统计字符时所用到的链表结构 typedef struct node char data; int number; struct node *next; data; /赫夫曼代码结构 typedef char* huffmancode; 14 / 32 /创建赫夫曼树 void creathuffmantree(huffmantree * /创建赫夫曼代码 void creathuffmancode(huffmantree *list, huffmancode /从文件中读取数据并计算各字符出现频率 void datacount(static * /文件编码程序 void fileencoding(); /创建文件编码 void creatfilecoding(); /导出编码后文件 void exportfileencoding(huffmantree *list, huffmancode code, int codesize); /导出文件中字符权重 void exportcharacterweight(); /文件译码程序 void filedecoding(); /导入编码后的文件 void inportfilecoding(); /导入文件中字符权重 void inportcharacterweight(); /显示译码后的文件内容 void displaycontext(); bool comparedata(char *tempcode, int void bound(char character, int size); /赫夫曼树 huffmantree *list; /赫夫曼代码 huffmancode code; /字符权重信息 static *info; /字符种数 int codesize; /文件名 char filename30; int main() char choice; 15 / 32 while (true) system(“cls“); printf(“ 赫夫曼编码加密程序n“); bound(-, 25); printf(“ 1. 文 件 编 码 n“); printf(“ 2. 文 件 译 码 n“); printf(“ 0. 退 出 程 序 n“); bound(-, 25); printf(“ 请选择: “); fflush(stdin); choice = getchar(); switch (choice) case 1: fileencoding(); break; case 2: filedecoding(); break; case 0: printf(“n“); system(“pause“); return 0; break; default: printf(“n 您的输入有误, 按任意键后请从新输入!“); getch(); break; void creathuffmantree(huffmantree * int lnode, rnode; int value1, value2; huffmantree *ptr; 16 / 32 limit = codesize * 2 - 1; if (list = (huffmantree *)malloc(sizeof(huffmantree) * limit) = null) printf(“ 内存不足, 操作失败!n“); exit(0); for(i=0, ptr=list; idata = infoi.data; ptr-weight = infoi.weight; ptr-parent = ptr-lchild = ptr-rchild = -1; for(; idata = 0; ptr-weight = 0; ptr-parent = ptr-lchild = ptr-rchild = -1; for(i=codesize; idata = ch; ptr-number = 1; ptr-next = characterlist.next; characterlist.next = ptr; +typenumber; else while (current != null) current = current-next; if (current != null) +(current-number); +characternumber; else 20 / 32 if (ptr = (data *)malloc(sizeof(data) = null) printf(“ 内存不足, 操作失败!n“); exit(0); ptr-data = ch; ptr-number = 1; ptr-next = current; previous-next = ptr; +typenumber; +characternumber; fclose(fp); codesize = typenumber; info = (static *)malloc(sizeof(static) * codesize); current = characterlist.next; for (int i=0; idata; infoi.weight = (int)(current-number * 100.0 / characternumber); current = current-next; void fileencoding() char choice; while (true) system(“cls“); printf(“ 文件编码程序n“); bound(-, 25); printf(“ 1. 创 建 文 件 编 码 n“); printf(“ 2. 导 出 文 件 编 码 n“); 21 / 32 printf(“ 3. 导 出 文 件 密 钥 n“); printf(“ 0. 返 回 主 菜 单 n“); bound(-, 25); printf(“ 请选择: “); fflush(stdin); choice = getchar(); switch (choice) case 1: creatfilecoding(); break; case 2: exportfileencoding(list, code, codesize); break; case 3: exportcharacterweight(); break; case 0: return; default: printf(“n 您的输入有误, 按任意键后请从新输入!“); getch(); break; void creatfilecoding() datacount(info); creathuffmantree(list, info, codesize); creathuffmancode(list, code, codesize); printf(“n 创建文件编码成功! 按任意键继续!“); getch(); void exportfileencoding(huffmantree *list, huffmancode code, int codesize) int i; char ch; char outfilename30; file *infile, *outfile; 22 / 32 system(“cls“); infile = fopen(filename, “rb“); printf(“n 请创建导出文件名: “); fflush(stdin); gets(outfilename); if (outfile = fopen(outfilename, “wb“) = null) printf(“ 输出文件创建失败!n“); exit(0); while (ch = fgetc(infile) != eof) for(i=0; idata = data; ptr-number = weight; ptr-next = characterlist.next; characterlist.next = ptr; +characternumber; fclose(fp); codesize = characternumber; if (info = (static *)malloc(sizeof(static) * codesize) = null) printf(“ 内存不足, 操作失败!n“); exit(0); ptr = characterlist.next; for (int i=codesize-1; i=0; -i) infoi.data = ptr-data; infoi.weight = ptr-number; ptr = ptr-next; printf(“n 文件导入成功! 下一步.n“); bool comparedata(char *tempcode, int position codesize; +position) if (strcmp(tempcode, codeposition) = 0) return true; 27 / 32 return false; void displaycontext() inportcharacterweight(); creathuffmantree(list, info, codesize); creathuffmancode(list, code, codesize); inportfilecoding(); file *fp; int position; int end; char *tempcode; char ch; fp = fopen(filename, “rb“); if (tempcode = (char *)malloc(sizeof(char) * codesize) = null) printf(“ 内存不足, 操作失败!n“); exit(0); end = 0; printf(“n 文件内容为:nn “); while (ch = fgetc(fp) != eof) tempcodeend = ch; +end; tempcodeend = 0; if (comparedata(tempcode, position) printf(“%c“, infoposition.data); end = 0; 28 / 32 printf(“nn 按任意键结束!“); getch(); void bound(char character, int size) while (size-) putchar(character); putchar(n); g an employment tribunal claim employment tribunals sort out disagreements between employers and employees. you may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly. for more information about dismissal and unfair dismissal, see dismissal. you can make a claim to an employment tribunal, even if you havent appealed against the disciplinary action your employer has taken against you. however, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal. remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. if your application is received after this time limit, the tribunal will not usually accept it. if you are worried about how the time limits apply to you, take advice from one of the organisations listed under further help. employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation. most people find making a claim to an employment tribunal challenging. if you are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed under further help. if you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. this is known as a damages-based agreement. in england and wales, your solicitor cant charge you more than 35% of your compensation if you win the case. if you are thinking about signing up for a damages-based agreement, you should make sure youre clear about the terms of the agreement. it might be best to get advice from an experienced adviser, for example, at a citizens advice bureau. to find your nearest cab, including those that give advice by e-mail, click on nearest cab. for more information about making a claim to an employment tribunal, see employment tribunals. the (lack of) air up there watch mcayman islands- based webb, the head of fifas anti-racism 29 / 32 taskforce, is in london for the football associations 150th anniversary celebrations and will attend citys premier league match at chelsea on sunday. “i am going to be at the match tomorrow and i have asked to meet yaya toure,“ he told bbc sport. “for me its about how he felt and i would like to speak to him first to find out what his experience was.“ uefa has opened disciplinary proceedings against cska for the “racist behaviour of their fans“ during citys 2-1 win. michel platini, president of european footballs governing body, has also ordered an immediate investigation into the referees actions. cska said they were “surprised and disappointed“ by toures complaint. in a statement the russian side added: “we found no racist insults from fans of cska.“ age has reached the end of the beginning of a word. may be guilty in his seems to passing a lot of different life became the appearance of the same day; may be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. always feel oneself should go to do something, or write something. twenty years of life trajectory deeply shallow, suddenly feel something, do it. 一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日 子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些 天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或 者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。 the end of our life, and can meet many things really do? 而穷尽我们的一生,又能遇到多少事情是真正地非做不可? during my childhood, think lucky money and new clothes are necessary for new year, but as the advance of the age, will be more and more found that those things are optional; junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance. 童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那 些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后, 自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要 了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句 点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场, 看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。 originally, this world, can produce a chemical reaction to an event, in addition to resolutely, have to do, and time. 30 / 32 原来,这个世界上,对某个事件能产生化学反应的,除了非做不可的坚决,还有,时 间。 a persons time, your ideas are always special to clear. want, want, line is clear, as if nothing could shake his. also once seemed to be determined to do something, but more often is he backed out at last. dislike his cowardice, finally found that there are a lot of love, there are a lot of miss, like shadow really have been doomed. those who do, just green years oneself give oneself an arm injection, or is a self-righteous spiritual. 一个人的时候,自己的想法总是特别地清晰。想要的,不想要的,界限明确,好像没 有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打 起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真 的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂, 或者说,是自以为是的精神寄托罢了。 at the moment, the sky is dark, the air is fresh factor after just rained. suddenly thought of blue plaid shirt; those were broken into various shapes of stationery; from the corner at the beginning of deep friendship; have declared the end of the encounter that havent start planning. those years, those days of do, finally, like youth, will end in our life. 此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬 衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友谊;还有那场还没有开始 就宣告了终结的邂逅计划那些年那些天的非做不可,终于和青春一样,都将在我们的 人生中谢幕。 baumgartner the disappointing news: mission aborted. r plays an important role in this mission. starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. the balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. it will climb higher than the tip of mount everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosph
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年商场售后服务外包合同
- 2025版木材产品溯源体系建立与应用合同
- 工业厂房工程保修承诺及设备保证措施
- 2025年度房产继承合同范本
- 2025年度医疗器械代工生产服务合同范本
- 2025年度办公大楼停车场管理与智能化升级服务合同
- 2025电力设施运维与维护施工设计合同
- 2025年度存量房买卖合同中的租客权益保护规定
- 2025版湿地公园土方开挖与生态修复工程承包合同
- 2025版融资咨询服务合同范本:人工智能产业版
- 新入职员工遵纪守法培训
- 中学新生入学培训
- 肿瘤科中医护理适应技术
- 专题:完形填空(含解析)六年级英语下册期末复习考点培优专项鲁教版(五四学制)(含答案解析)
- 口腔科护士核心职责与操作规范
- 死亡病例讨论病例汇报
- 人教版(2024)八年级(下)期末物理试卷(含解析)
- 期末真题演练卷(试题) 数学七年级下册北师大版(2024版)
- 人教版小升初语文试卷及答案【完整版】
- 武汉版三年级生命安全教育全册教案
- 农商行资本管理制度
评论
0/150
提交评论