欢迎来到天天文库
浏览记录
ID:17133567
大小:244.50 KB
页数:19页
时间:2018-08-27
《信息论与编码实验报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include#include#includeusingnamespacestd;typedefstruct{intweight;intflag;intparent;intlchild;intrchild;}hnodetype;typedefstruct{intbit[10];intstart;charleaf;}hcodetype;voidhuf(charcha[],intm[],intn){inti,j,m1,m2,x1,x2,c,p;hnode
2、type*huffnode=newhnodetype[2*n-1];hcodetype*huffcode=newhcodetype[n],cd;for(i=0;i<2*n-1;i++){//初始化哈夫曼树huffnode[i].weight=0;huffnode[i].parent=0;huffnode[i].flag=0;huffnode[i].lchild=-1;huffnode[i].rchild=-1;}for(i=0;i3、];huffcode[i].leaf=cha[i];}for(i=0;i4、ters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcamem2=m1;x2=x1;m1=huffnode[j].weight;x1=j;}elseif(huffnode[j].weight<=m2&&huffnode[j].flag==0){m2=huffnode[j].weight;x2=j;}}huffnode[x1].parent=n+i;huffnode[x2].parent=n+i;5、huffnode[x1].flag=1;huffnode[x2].flag=1;huffnode[n+i].weight=huffnode[x1].weight+huffnode[x2].weight;huffnode[n+i].lchild=x1;huffnode[n+i].rchild=x2;}for(i=0;i6、cd.start]=0;elsecd.bit[cd.start]=1;cd.start--;c=p;p=huffnode[c].parent;}cout<7、ang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcamedelete[]huffnode;}voidmain(){inti=0;//intm[10]={30,23,10,10,9,8,7,3};charcha[10]="abcd8、efgh";floatf;intm[10];printf("请输入概率的小数点后两位值");for(i=0,i<10,i++)scanf("%d",&a[i]);cout<<"该字符串为:t";for(i=0;i
3、];huffcode[i].leaf=cha[i];}for(i=0;i4、ters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcamem2=m1;x2=x1;m1=huffnode[j].weight;x1=j;}elseif(huffnode[j].weight<=m2&&huffnode[j].flag==0){m2=huffnode[j].weight;x2=j;}}huffnode[x1].parent=n+i;huffnode[x2].parent=n+i;5、huffnode[x1].flag=1;huffnode[x2].flag=1;huffnode[n+i].weight=huffnode[x1].weight+huffnode[x2].weight;huffnode[n+i].lchild=x1;huffnode[n+i].rchild=x2;}for(i=0;i6、cd.start]=0;elsecd.bit[cd.start]=1;cd.start--;c=p;p=huffnode[c].parent;}cout<7、ang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcamedelete[]huffnode;}voidmain(){inti=0;//intm[10]={30,23,10,10,9,8,7,3};charcha[10]="abcd8、efgh";floatf;intm[10];printf("请输入概率的小数点后两位值");for(i=0,i<10,i++)scanf("%d",&a[i]);cout<<"该字符串为:t";for(i=0;i
4、ters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcamem2=m1;x2=x1;m1=huffnode[j].weight;x1=j;}elseif(huffnode[j].weight<=m2&&huffnode[j].flag==0){m2=huffnode[j].weight;x2=j;}}huffnode[x1].parent=n+i;huffnode[x2].parent=n+i;
5、huffnode[x1].flag=1;huffnode[x2].flag=1;huffnode[n+i].weight=huffnode[x1].weight+huffnode[x2].weight;huffnode[n+i].lchild=x1;huffnode[n+i].rchild=x2;}for(i=0;i6、cd.start]=0;elsecd.bit[cd.start]=1;cd.start--;c=p;p=huffnode[c].parent;}cout<7、ang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcamedelete[]huffnode;}voidmain(){inti=0;//intm[10]={30,23,10,10,9,8,7,3};charcha[10]="abcd8、efgh";floatf;intm[10];printf("请输入概率的小数点后两位值");for(i=0,i<10,i++)scanf("%d",&a[i]);cout<<"该字符串为:t";for(i=0;i
6、cd.start]=0;elsecd.bit[cd.start]=1;cd.start--;c=p;p=huffnode[c].parent;}cout<7、ang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcamedelete[]huffnode;}voidmain(){inti=0;//intm[10]={30,23,10,10,9,8,7,3};charcha[10]="abcd8、efgh";floatf;intm[10];printf("请输入概率的小数点后两位值");for(i=0,i<10,i++)scanf("%d",&a[i]);cout<<"该字符串为:t";for(i=0;i
7、ang,deferthenextdayfocusedontheassassination.Linping,Zhejiang,1ofwhichliquorwinemasters(WuzhensaidinformationisCarpenter),whogotAfewbayonets,duetomissedfatal,whennightcamedelete[]huffnode;}voidmain(){inti=0;//intm[10]={30,23,10,10,9,8,7,3};charcha[10]="abcd
8、efgh";floatf;intm[10];printf("请输入概率的小数点后两位值");for(i=0,i<10,i++)scanf("%d",&a[i]);cout<<"该字符串为:t";for(i=0;i
此文档下载收益归作者所有