huffman树压缩文件程序(Huffman tree compressed file program).docVIP

  • 0
  • 0
  • 约 16页
  • 2017-08-31 发布于河南
  • 举报

huffman树压缩文件程序(Huffman tree compressed file program).doc

huffman树压缩文件程序(Huffman tree compressed file program)

huffman树压缩文件程序(Huffman tree compressed file program) Huffman tree compression file program (share with you ah) 2008-06-28 21:41 (| classification: default classification) Six, detailed design: (ha ha,, after you see, dont forget to leave footprints!) #include stdafx.h #include stdio.h #include string.h #include stdlib.h #include conio.h Struct head { Unsigned char b; Long count; Long, parent, LCH, rch; Char bits[256]; } Header[512], tmp; Void, compress () { Char, filename[255], outputfile[255], buf[512]; Unsigned char c; Long, I, J, m, N, f; Long, Min1, pT1, flength, length1, length2; Double div; FILE, *ifp, *ofp; Printf (please, enter, your, file, name (for, example:luyifa.txt):\n); Gets (filename); Ifp=fopen (filename, Rb); If (ifp==NULL) { Printf (\n, opening, file, is, fail, \n\n); Return; } Printf (please, enter, compressed, file, name (for, example:618.txt):\n); Gets (outputFile); Ofp=fopen (strcat (outputFile, .Txt), WB); If (ofp==NULL) { Printf (\n, Compressing, file, is, fail, \n\n); Return; } Flength=0; While (... Feof (IFP)) { FREAD (c, 1,1, IFP); Header[c].count++; Flength++; } Flength--; Length1=flength; Header[c].count--; For (i=0; i512; i++) { If (header[i].count, =0) header[i].b= (unsigned, char) i; Else header[i].b=0; Header[i].parent=-1; header[i].lch=header[i].rch=-1; } For (i=0; i256; i++) { For (j=i+1; j256; j++) { If (header[i].countheader[j].count) { Tmp=header[i]; Header[i]=header[j]; Header[j]=tmp; } } } For (i=0; i256; i++) If (header[i].count==0) Break; N=i; M=2*n-1; For (i=n; im; i++) { Min1=999999999; For (j=0; ji; j++) { If (header[j].parent, =-1) continue; If (min1header[j].count) { Pt1=j; Min1=header[j].count; Continue; } } Header[i].count=header[pt1].count; Header[pt1].parent=i; Header[i].lch=pt1; Min1=999999999; For (j=0; ji; j++) { If (header[j].parent, =-1) continue; If (min1header[j].count) { Pt1=j; Min1=header[j].count; Continue; } } Header[i].count+=header[pt1].count; Header[i].rch=pt1; Header[pt1].parent=i; } For (i=0; in; i++

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档