資源簡介
實現霍夫曼編碼,以泰戈爾《飛鳥集》為例,對其中的26個字母出現的次數進行霍夫曼編碼
代碼片段和文件信息
#include?
#include?
#include??
?
typedef?struct?huffman_node?
{
int?data;
int?lchild;
int?rchild;
int?parent;
}bnode;??//定義二叉鏈表結點結構
typedef?char?*?HCode;
HCode?*HC=(HCode?*)malloc(26*sizeof(HCode));?
void?SelectIJ(int?k?bnode?node[]?int?&i?int?&j)//選擇根結點權值最小的兩個結點?
{
int?m1m2;
for(m1=1;m1<=k;m1++)
???if(!node[m1].parent){
??i?=m1;
??break;
???}
for(m2=m1+1;m2<=k;m2++)
???if(!node[m2].parent){
??j?=?m2;
??break;
???}
for(m1=1;m1<=k;m1++)
???if((node[i].data>node[m1].data)&&(!node[m1].parent)&&(j!=m1))
??????i?=?m1;
for(m2=1;m2<=k;m2++)??
???if((node[j].data>node[m2].data)&&(!node[m2].parent)&&(i!=m2))
??????????j?=?m2;
}
void?HuffmanTree(int?n?bnode?node[]int?w[])
{
int?impcdlen;
int?s1
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????3228??2018-10-26?19:41??軟件基礎_3170105928_蔣楊帆_哈夫曼編碼\Huffman.cpp
?????文件???????43248??2018-10-26?19:47??軟件基礎_3170105928_蔣楊帆_哈夫曼編碼\Huffman.exe
?????文件???????31911??2010-09-26?22:23??軟件基礎_3170105928_蔣楊帆_哈夫曼編碼\StrayBirds.txt
?????目錄???????????0??2018-10-26?19:47??軟件基礎_3170105928_蔣楊帆_哈夫曼編碼\
評論
共有 條評論