哈夫曼树及哈夫曼编码译码的实现程序如下:#include""#include""#include""#include""intmaxline=0;charxx[50][80];intl,L;typedefstruct/*定义结构体*/{intweight;intparent;intlchild,rchild;}tree;treeb[57];intReadDat(void){FILE*fp;inti=0;char*p;if((fp=fopen("","r"))==NULL)return1;while(fgets(xx[i],80,fp)!=NULL){p=strchr(xx[i],'\n');if(p)*p=0;i++;}maxline=i;fclose(fp);return0;}intpinlv(inta[]){inti,j;intL;for(i=0;i<maxline;i++){L=strlen(xx[i]);for(j=0;j<L;j++)if(xx[i][j]>=97&&xx[i][j]<=122)a[xx[i][j]-97]++;elseif(xx[i][j]==32)a[26]++;elseif(xx[i][j]==44)a[27]++;elseif(xx[i][j]==46)a[28]++;}}smax(inta[],intlow,inthigh,intmax[]){intmid,M[2],N[2];mid=(high+low)/2;if(high-low==1){if(a[low]<a[high]){max[0]=low;max[1]=high;}else{max[0]=high;max[1]=low;}}elseif(high-low==0){max[0]=high;max[1]=57;}else{smax(a,low,mid,max);M[0]=max[0];M[1]=max[1];smax(a,mid+1,high,max);N[0]=max[0];N[1]=max[1];if(a[M[0]]<=a[N[0]]&&a[M[1]]<=a[N[0]]){max[0]=M[0];max[1]=M[1];}elseif(a[M[0]]<=a[N[0]]&&a[M[1]]>a[N[0]]){max[0]=M[0];max[1]=N[0];}elseif(a[M[0]]>a[N[0]]&&a[M[0]]<=a[N[1]]){max[0]=N[0];max[1]=M[0];}elseif(a[M[0]]>a[N[0]]&&a[M[0]]>a[N[1]]){max[0]=N[0];max[1]=N[1];}}}bhtree(inta[]){inti,j;intmax[2];intc[58]={0};c[57]=4000;l=0;for(i=0;i<29;i++){if(a[i]!=0){b[i].weight=a[i];b[i].lchild=0;b[i].rchild=0;c[i]=a[i];l++;}elseif(a[i]==0){b[i].weight=a[i];b[i].lchild=0;b[i].rchild=0;c[i]=4000;}}for(i=29;i<29+
哈夫曼树及哈夫曼编码译码的实现 来自淘豆网m.daumloan.com转载请标明出处.