




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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详细设计 开始初始化哈夫曼链 表p-weight=countip=p-nextfor(i=n;iparent=ht
2、2-parent=pp-lchild=ht1p-rchild=ht2p-weight=ht1-weight+ht2-结束 开始hci.code-hci.start=1if(q=q-parent-lchild)hci.code-hci.start=0p=p-nexti=n 时结束 开始p!=rootsk+=strjp=root结束6调试分析7用户使用说明 2 输入 n 个字符和 n 个权值4 退出系统8测试结果 9附录#include stdio.h#include stdlib.h#include string.h#define max 100struct hafnodeint weight;
3、int parent;char ch;int lchild;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.wei
4、ght=s1+s2;myhafftreei.lchild=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(myha
5、fftreef.lchild=c) cd-start=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 wo
6、rds:n);scanf(%d,&n);m=2*n-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 c
7、aozuo_d(int n)int i,c;char 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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 智能制造转型中个性化定制如何突破10件套标准化生产惯性
- 2025年武术段位制一级考试试题及答案
- 水处理技术考试题及答案
- 美容仪器行业2025市场潜力挖掘:技术创新与推广策略研究报告
- 新型导热系数分级墙板在多温区冷库中的能耗优化路径
- 2025年5G网络的网络安全挑战与解决方案
- 微通道分液管在超临界流体分离领域的传质效率瓶颈
- 微型化力矩电机热管理技术对性能衰减的影响评估
- 钣金加工废料回收与再利用方案
- 循环经济视域下木屑资源化利用的路径探索
- 培训部数据安全事项课件
- 保密观考试题及答案2025保密观知识竞赛试题及答案
- 保安部安全培训教学课件
- 老年综合征与护理试题及答案
- 3.2《参与民主生活》教案 2025-2026学年度道德与法治九年级上册 统编版
- 研发投入工时管理办法
- 道路升降柱安装合同范本
- 维护残疾人合法权益课件
- 社团招新课件
- 003-04-PFMEA第五版表格模板-(带实例)-2020.2.3
- 防渗漏、开裂监理实施细则
评论
0/150
提交评论