




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 算法与数据结构课程设计 a.编/译码系统应具有以下功能:(4)p:印代码文件(print)。将文件 codefile 以紧凑格式显示在终端上,每行 50 个代码。同时将此字符形式的编码文件写入文件 codeprin中。b.测试数据(1)利用下面这道题中的数据调试程序。字符 空格 ao频度 57 63 15 1 48 51 80 23 8 18 1 16 13需求分析3.1 程序的基本功能 测试数据要求本程序中测试数据主要为字符型文件。1.系统结构图(功能模块图)编码2功能模块说明5详细设计 开始初始化哈夫曼链 表且有 2n-1 个节点for(i=n;iparent=ht2-parent=pp
2、-lchild=ht1p-rchild=ht2p-weight=ht1-weight+ht2-结束 开始hci.code-hci.start=1p=p-nexti=n 时结束 开始p!=rootp-lchild=null&p-rchild=nullsk+=strjp=root结束6调试分析7用户使用说明 2 输入 n 个字符和 n 个权值4 退出系统8测试结果 9附录#include stdio.h#include stdlib.h#include string.h#define max 100struct hafnodeint weight;int parent;char ch;int lc
3、hild;int rchild;*myhafftree;struct codingchar bitmax;char ch;int weight;*myhaffcode;void haffman(int n)/* 构造哈弗曼树 */int i,j,x1,x2,s1,s2; s1=s2=10000;x1=x2=0;x1=j;else if(myhafftreej.parent=0&myhafftreej.weights2)x2=j;myhafftreex1.parent=i;myhafftreex2.parent=i;myhafftreei.weight=s1+s2;myhafftreei.lch
4、ild=x1;myhafftreei.rchild=x2;void haffmancode(int n)int start,c,f,i,j,k;char *cd;cd=(char *)malloc(n*sizeof(char);myhaffcode=(struct coding *)malloc(n+1)*sizeof(struct coding);cdn-1=0;for(i=1;i=n;+i)start=n-1;for(c=i,f=myhafftreei.parent;f!=0;c=f,f=myhafftreef.parent)if(myhafftreef.lchild=c) cd-star
5、t=0;else cd-start=1;for(j=start,k=0;jn;j+)myhaffcodei.bitk=cdj;k+;myhaffcodei.ch=myhafftreei.ch; void print()*n);printf(* *n);printf(* *n);printf(* *n);2.coding3.codeprinting 4.print the huffman5.exitprintf(*n);int i,n,m;printf(now initn);printf(please input the number of words:n);scanf(%d,&n);m=2*n
6、-1;myhafftree=(struct hafnode *)malloc(sizeof(struct hafnode)*(m+1);for(i=1;i=n;i+)for(i=n+1;i=m;i+)myhafftreei.ch =#; haffmancode(n);printf(n);scanf(%s,string);n=strlen(string);for(i=1,p=string;i=n;i+,p+)for(j=1;j=m;j+)if(myhaffcodej.ch=*p)printf(%sn,myhaffcodej.bit);void caozuo_d(int n)int i,c;cha
7、r code1000,*p;printf(please input the coding:n);scanf(%s,code);for(p=code,c=2*n-1;*p!=0;p+)if(*p=0)c=myhafftreec.lchild;if(myhafftreec.lchild=0)printf(%c,myhafftreec.ch);c=2*n-1;continue; c=myhafftreec.rchild;if(myhafftreec.lchild=0)printf(%c,myhafftreec.ch);c=2*n-1;continue;printf(n);printf(%c %d %d %d %dn,myhafftreei.ch,myhafftreei.weight,myhafftreei.lchild,myhafftreei.rchild,myhafftreei.parent);main()int n;char char1;print()
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 法律文化在法治建设中的作用与价值试题及答案
- 班主任与学生沟通技巧的提升计划
- 软考网络管理员备考计划试题及答案
- 人才招聘与培养计划
- 结合客户反馈优化生产流程计划
- 自然语言处理技术进展试题及答案
- 2024年沈阳工程学院辅导员考试真题
- 2025年法学概论百科全书式试题及答案
- 2024年吉林省医疗保障局下属事业单位真题
- 2024年塔城地区中医医院招聘笔试真题
- 店面出让股权协议书
- 英文电影鉴赏知到智慧树期末考试答案题库2025年北华大学
- 心理健康课件主题班会
- 2025年家政服务行业考核考试试题及答案
- 美容诊所合作协议书
- 江苏省南通市2025届高三三模语文试题(含答案)
- 护理6大核心制度
- 2025年高考英语考前热点话题押题卷(新高考Ⅰ卷)-2025年高考英语模拟考试(解析版)
- 旅游退团协议书
- 中外航海文化知到课后答案智慧树章节测试答案2025年春中国人民解放军海军大连舰艇学院
- 复调音乐巡礼-巴赫勃兰登堡协奏曲 课件-2023-2024学年高中音乐人音版(2019)必修音乐鉴赏
评论
0/150
提交评论