欢迎来到天天文库
浏览记录
ID:55689105
大小:17.50 KB
页数:5页
时间:2020-05-25
《哈夫曼编码C语言程序.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、附录一:哈夫曼编码分析与实现C语言源程序#include#include#definew10floata[w],b[w][w]={0},f[w]={0};inti,c[w][w][w],d[w]={0},m;xiaoxi(){intn;floatP=0;printf("请分别输入消息概率a");for(n=0;n=1
2、
3、a[n]<=0){printf("出错,概率应在[0,1]范围内
4、n");return(0);break;}P+=a[n];}if(P!=1){printf("出错,概率和应为1");return(0);}elsereturn(1);}ordination(intf,float*e){intg,j;floatk;for(g=0;g5、+1][1][0]=1;for(;i>=0;i--){t=0;for(k=m-2-i;k>=0;k--){if((f[i]==b[i+1][k])&&(t==0)){t=1;for(r=0;c[i+1][k][r]!=2;r++){c[i][m-i-2][r]=c[i+1][k][r];c[i][m-i-1][r]=c[i+1][k][r];}c[i][m-i-2][r]=0;c[i][m-i-1][r]=1;}}for(j=m-i-3;j>=0;j--)for(k=m-2-i;k>=0;k--6、)if(b[i][j]==b[i+1][k])for(r=0;c[i+1][k][r]!=2;r++)c[i][j][r]=c[i+1][k][r];}}add(){intj;for(i=0;i7、}}main(){intn,x,y;floatK=0,H=0;for(n=0;n8、n+1);for(x=0;x9、(a[n]))/log10l(2);printf("t其码长为:%d",d[n]);}printf("平均码长K=");printf("%3.2f",K);printf("信源熵=%3.2f",H);printf("编码效率η=(H/K)=%3.2f%%",H*100/K);printf("冗余度γ=(1-η)=%3.2f",1-H/K);}}
5、+1][1][0]=1;for(;i>=0;i--){t=0;for(k=m-2-i;k>=0;k--){if((f[i]==b[i+1][k])&&(t==0)){t=1;for(r=0;c[i+1][k][r]!=2;r++){c[i][m-i-2][r]=c[i+1][k][r];c[i][m-i-1][r]=c[i+1][k][r];}c[i][m-i-2][r]=0;c[i][m-i-1][r]=1;}}for(j=m-i-3;j>=0;j--)for(k=m-2-i;k>=0;k--
6、)if(b[i][j]==b[i+1][k])for(r=0;c[i+1][k][r]!=2;r++)c[i][j][r]=c[i+1][k][r];}}add(){intj;for(i=0;i7、}}main(){intn,x,y;floatK=0,H=0;for(n=0;n8、n+1);for(x=0;x9、(a[n]))/log10l(2);printf("t其码长为:%d",d[n]);}printf("平均码长K=");printf("%3.2f",K);printf("信源熵=%3.2f",H);printf("编码效率η=(H/K)=%3.2f%%",H*100/K);printf("冗余度γ=(1-η)=%3.2f",1-H/K);}}
7、}}main(){intn,x,y;floatK=0,H=0;for(n=0;n8、n+1);for(x=0;x9、(a[n]))/log10l(2);printf("t其码长为:%d",d[n]);}printf("平均码长K=");printf("%3.2f",K);printf("信源熵=%3.2f",H);printf("编码效率η=(H/K)=%3.2f%%",H*100/K);printf("冗余度γ=(1-η)=%3.2f",1-H/K);}}
8、n+1);for(x=0;x9、(a[n]))/log10l(2);printf("t其码长为:%d",d[n]);}printf("平均码长K=");printf("%3.2f",K);printf("信源熵=%3.2f",H);printf("编码效率η=(H/K)=%3.2f%%",H*100/K);printf("冗余度γ=(1-η)=%3.2f",1-H/K);}}
9、(a[n]))/log10l(2);printf("t其码长为:%d",d[n]);}printf("平均码长K=");printf("%3.2f",K);printf("信源熵=%3.2f",H);printf("编码效率η=(H/K)=%3.2f%%",H*100/K);printf("冗余度γ=(1-η)=%3.2f",1-H/K);}}
此文档下载收益归作者所有