欢迎来到天天文库
浏览记录
ID:9415473
大小:265.50 KB
页数:10页
时间:2018-04-30
《哈夫曼算法压缩和解压字符串》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、2010-12-0222:39[原]文件编码2用哈夫曼算法压缩和解压字符串#include#include#include//char*chrs="Atthehighestlevelofabstraction,therearethreebasicdrawingoperations:clearingthewindow,drawingageometricobject,anddrawingarasterobject.Rasterobjects,whichincludesuchthings
2、astwo-dimensionalimages,bitmaps,andcharacterfonts,arecoveredinChapter8.Inthischapter,youlearnhowtoclearthescreenandtodrawgeometricobjects,includingpoints,straightlines,andflatpolygons. ";//char*chrs="kgasdgalfjsladd ";char*chrs="fsskffffaavbbbcscscscs ";intasciiCharsCo
3、unt[128];charcurrlCodeChrs[9];intcharCountSize=0;longtotalUrlLength=0;longtotalUrlOffset=0;intcurrlMinValueIndex=-1;//当前最小值的索引char*resultBinString;//二进制字符串longbinStringIndex=0;//二进制字符索引char*resultBytes;//编码后的字节intresultByteSize=0;//编码后字节的数量typedefstructtreeNode{//树节点 ch
4、arnodename;//代表的字符 intnodeFlag;//1:叶节点,0:根节点 intweight;//权值,字符的频率 char*url;//路径 }TreeNode;//==================================================voidinitCharCount(){ inti=0; memset(&asciiCharsCount,0,sizeof(asciiCharsCount)); for(i=0;i<(int)(strlen(chrs));i++){
5、 intcurlChar=(int)(chrs[i]); asciiCharsCount[curlChar]=asciiCharsCount[curlChar]+1; }}intgetMinValue(){//查找数量大于0,并且最小的索引 intrelIndex=-1; intminValue=(int)(strlen(chrs)); inti=0; for(i=0;i<128;i++){ if(asciiCharsCount[i]>0){ if(minValue>asc
6、iiCharsCount[i]){ minValue=asciiCharsCount[i]; relIndex=i; } } } returnrelIndex;}voidbinChrsToByte(){ inti=0; charhChrs[5]; charlChrs[5]; intresultValue=0x00; charbTable[65]="000000010010001101000101011001111000100110101
7、0111100110111101111 "; for(i=0;i<4;i++){ hChrs[i]=currlCodeChrs[i]; lChrs[i]=currlCodeChrs[i+4]; } hChrs[4]=' '; lChrs[4]=' '; for(i=0;i<16;i++){ intj=0; intisEqul=1; for(j=0;j<4;j++){ if(hChrs[j]==bTable[(i*4)+j]){
8、 if(isEqul==4){//如果四个字符都相同 resultValue=i*16; } isEqul++;
此文档下载收益归作者所有