資源簡介
任務 :對一篇英文文章,統計各字符出現的次數,實現Huffman編碼;
要求:輸出每個字符出現的次數和編碼,其中求最小權值要求用堆實現;
注意:在Huffman編碼后,要將編碼表和英文文章編碼結果保存到文件中,并提供讀編碼文件生成原文件的功能。
代碼片段和文件信息
#include
#include
#include
#include
#include
#include
#define?MAX?30
#define?MAXWEIGHT??30000
typedef?struct{
int?key;
int?position;
}redtype?;
typedef?struct{
redtype?r[27];
int?length;
}sqlist;
typedef?struct{
char?data;
int?weight;
int?parent;
int?lchild;
int?rchild;
}huffnode*huffmantree;//赫夫曼結點
typedef?struct{
char?cd[MAX];
int?start;
}huffcode*huffmancode;//赫夫曼編碼
char?codefilenm[81];//翻譯后保存的文件名codefilenm
?????????????????????//此文件在編碼和譯碼時都有需要
huffmantree?ht;
??huffmancode?hc;
int?count[27];
int?leafnum=26;
?char?letter[28]={‘@‘‘a‘‘b‘‘c‘‘d‘‘e‘‘f‘‘g‘‘h‘‘i‘‘j‘‘k‘‘l‘
‘m‘‘n‘‘o‘‘p‘‘q‘‘r‘‘s‘‘t‘‘u‘‘v‘‘w‘‘x‘‘y‘‘z‘‘\0‘};//@鍵代表不是英文字符的其他數符;
?
//函數名:in
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2175??2008-01-11?19:51??赫夫曼編碼\input.txt
?????文件????????638??2008-01-09?13:22??赫夫曼編碼\mine.txt
?????文件????????638??2008-01-11?19:52??赫夫曼編碼\my.txt
?????文件?????112561??2008-01-11?19:56??赫夫曼編碼\哈夫曼編寫編譯碼.rtf
?????文件??????12374??2008-01-11?19:57??赫夫曼編碼\赫夫曼?.cpp
?????目錄??????????0??2013-01-24?16:21??赫夫曼編碼
-----------?---------??----------?-----??----
???????????????128386????????????????????6
- 上一篇:基于ZIGBEE智能紅綠燈控制系統應用方案
- 下一篇:慣性導航推算包括數據
評論
共有 條評論