資源簡介
根據給定字符的使用頻率,為其設計哈夫曼編碼。 功能:求出n個字符的哈夫曼編碼。輸入:輸入n個字符和字符在電文中的使用頻率。輸出:n個字符的哈夫曼編碼。
代碼片段和文件信息
#include????
#include????
#include?????
#include?????
#include?????
#include????
//------定義結構體---------?
typedef???struct???{?
char??data;???//字符
????int???weight;??//字符的權值,即出現次數
int???parent;??//父節點
int???lchild;??
int???rchild;??
}?HTNode*HuffmanTree;??
typedef?char?**HuffmanCode;??//編碼指針
?
typedef?struct?{??
int?s1;??//權值最小的兩個序號
int?s2;??
}?MinCode;??
//-------方法聲明----------
void?Welcome();
//void?Error(char?*message);???//錯誤信息處理
HuffmanCode?HuffmanCoding(HuffmanTree?HTHuffmanCode?HCint?*wchar?*dint?n);??//給字符編碼
MinCode?Select(HuffmanTree?HTint?n);??//選出最短?
//-------方法定義----------?
void?Welcome()
{
//system(“color?8a“);//設置系統顏色
printf(“???????????????========================???\n“);
printf(“***************歡迎使用本哈夫曼編碼系統**************\n“);
printf(“???????????????========================???\n“);
printf(“!接下來請輸入相關數據,就會得到你所需要的哈夫曼編碼。\n“);
}
/*void?Error(char?*message)??
{??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4972??2009-11-27?23:26??哈夫曼編碼.cpp
?????文件????????145??2009-11-18?22:24??readme.txt
?????文件?????200786??2009-11-23?21:39??哈夫曼編碼.exe
-----------?---------??----------?-----??----
???????????????205903????????????????????3
評論
共有 條評論