資源簡介
用DEVC++編譯實現。一個完整的系統應具有以下功能:
(1)I:初始化(Initialization)。從終端讀入字符集大小n,以及n個字符和n個權值,建立哈夫曼樹,并將它存于文件hfmTree中。
(2)E:編碼(Encoding)。利用已建好的哈夫曼樹(如不在內存,則從文件htmTree中讀入),對文件ToBeTran中的正文進行編碼,然后將結果存入文件CodeFile中。
(3)D:譯碼(Decoding)。利用已建好的哈夫曼樹將文件CodeFile中的代碼進行譯碼,結果存入文件TextFile中。
(4)P:印代碼文件(Print)。將文件CodeFile以緊湊格式顯示在終端
代碼片段和文件信息
//#include?
#include?
#include?
#include?
#include?
using?namespace?std;
typedef?struct?
{
float?weight;
int?parentlchildrchild;
}HTNode*?HuffmanTree;
typedef?char?**HuffmanCode;
HuffmanTree?HT;//定義全局變量?
HuffmanCode?HC;
float?*w;
int?ijn;
char?*z;?
int?flag=0;
int?numb=0;
int?min(HuffmanTree?tint?i)//哈夫曼編碼?
{?//?函數void?select()調用
int?jflag;
float?k=1000;
for(j=1;j<=i;j++)
if(t[j].weight k=t[j].weightflag=j;
t[flag].parent=1;
return?flag;
}
void?select(HuffmanTree?tint?iint?&s1int?&s2)?//select函數
{?//?s1為最小的兩個值中序號小的那個
int?j;
s1=min(ti);
s2=min(ti);
if(s1>s2)
{
j=s1;
s1=s2;
s2=j;
}??//若s1>s2則s1與s2互換
}
void?HuffmanCoding(HuffmanTree?&HTHuffmanCode?&HC?float?*
- 上一篇:共軛梯度法求解偏微分方程MPI并行的c++實現
- 下一篇:大地測量學程序設計VC++
評論
共有 條評論