实验一哈夫曼编码.ppt

上传人:牧羊曲112 文档编号:6270411 上传时间:2023-10-12 格式:PPT 页数:12 大小:241.32KB
返回 下载 相关 举报
实验一哈夫曼编码.ppt_第1页
第1页 / 共12页
实验一哈夫曼编码.ppt_第2页
第2页 / 共12页
实验一哈夫曼编码.ppt_第3页
第3页 / 共12页
实验一哈夫曼编码.ppt_第4页
第4页 / 共12页
实验一哈夫曼编码.ppt_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《实验一哈夫曼编码.ppt》由会员分享,可在线阅读,更多相关《实验一哈夫曼编码.ppt(12页珍藏版)》请在三一办公上搜索。

1、实验一 哈夫曼编码,实验目的掌握哈夫曼编码原理理解数据压缩的实现过程,实验要求,根据哈夫曼编码算法,对下列信源实现哈夫曼编码。求出编码后的平均码长。,实验内容与步骤,1、实验内容 对上面信源进行哈夫曼编码。显示出每个符号的分配代码及平均码长2、实验步骤(1)初始化,根据符号概率的大小按由大到小顺序对符号进行排序。(2)把概率最小的两个符号组成一个节点。(3)重复步骤(1)(2),直到概率和为1(4)从根节点开始到相应于每个符号的“树叶”,概率大的标“0”,概率小的标“1”(5)从根节点开始,对符号进行编码。,实验结果要求,1、哈夫曼编码程序。2、实验报告(含流程图),0.230.210.180

2、.150.130.070.03,概率,1,0,0.10,1,0,0.23,1,0,0.33,1,0,0.44,1,0,0.56,0,1,1,A1A2A3A4A5A6A7,符号,哈夫曼编码举例,#include#include#define N 15#define M 2*N-1typedef structfloat weight;int parent,lchild,rchild;HTNode;typedef structchar data;float weight;char codeN;HTCode;,参考程序,void Init(HTCode hc,int*n)int i;printf(n

3、input n=);scanf(%d,参考程序(续),void Select(HTNode ht,int k,int*s1,int*s2)int i;for(i=1;i=k;i+)if(hti.parent=0)*s1=i;break;for(i=1;i=k;i+)if(hti.parent=0,参考程序(续),for(i=1;i=k;i+)if(hti.parent=0,参考程序(续),void HuffmanCoding(HTNode ht,HTCode hc,int n)char cdN;int i,j,m,c,f,s1,s2,start;m=2*n-1;for(i=1;i=m;i+)i

4、f(i=n)hti.weight=hci.weight;else hti.weight=0.0;hti.parent=hti.lchild=hti.rchild=0;for(i=n+1;i=m;i+)Select(ht,i-1,参考程序(续),for(i=1;i=m;i+)printf(n the%d charactor weight is%f:,i,hti.weight);printf(n the%d charactor lchild is%d:,i,hti.lchild);printf(n the%d charactor rchild is%d:,i,hti.rchild);printf(n the%d charactor parent is%d:,i,hti.parent);for(i=0;iN;i+)cdi=;cdn-1=0;for(i=1;i=n;i+)start=n-1;for(c=i,f=hti.parent;f;c=f,f=htf.parent)if(htf.lchild=c)cd-start=0;else cd-start=1;strcpy(hci.code,参考程序(续),void main()int i,m,n,wN+1;float l=0.0;float arg,*point=,参考程序(续),

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号