91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 154KB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2021-08-13
  • 語言: 其他
  • 標簽: 數據結構??C++??

資源簡介

利用哈夫曼編碼對數據進行無損壓縮,實現Huffman壓縮的編碼器和譯碼器。 1.首先讀入待壓縮源文件。 2.然后建立并分析字母表,對每種字符的出現頻度進行統計,以頻度作為建立Huffman樹的權值。 3. 頻度表建好后,就可以根據算法建立Huffman樹,對出現的每種字符進行Huffman編碼。 4. 此時,再次讀入源文件,逐字節編碼,將得到的編碼流寫入到磁盤文件。 5. 譯碼過程先讀入被壓縮的文件,將其解釋為比特流,根據Huffman樹,對比特流逐位譯碼,將譯碼結果逐次寫入到磁盤文件。

資源截圖

代碼片段和文件信息

#include
#include???
#include???
#include???
////////////////////////////////////////////////??
/***************?用于壓縮的編碼?***************/??
char?*t?=?“?!\“#$%&\‘()*+-./0123456789:;\
<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_‘abc\
defghijklmnopqrstuvwxyz{|}~“;??
?
//#define?DIGIT?6?//?binary“111111“?==?decimal“63“??
const?DIGIT=6;
?
char?IntToChar(int?x)??
{???
????return?t[x];??
}??
?
int?CharToInt(char?c)???
{??
????for?(int?i=0;?i????{??
????????if?(c?==?t[i])?
{??
????????????return?i;??
????????}??
????}??
}??
/**********************************************/??
////////////////////////////////////////////////??
?
int?main()??
{??
????void?Coding();??
????void?Decode();??
????char?s[10];??
?????
cout< cout<?????
cin>>s;
????if?(s[0]?==?‘1‘)?
{??
????????Coding();??
????}??
????else?if?(s[0]?==?‘2‘)?
{??
????????Decode();??
????}??
????else?{??
cout<????}??
????fclose(stdout);??
?????
????return?0;??
}??
?
const?RANGE?=?256;
?
//定義赫夫曼樹節點??
typedef?struct?{??
????int?w;?//?權值??
????int?p?l?r;?//?雙親?左孩子?右孩子??
????char?*cd;?//對應編碼??
}?node;??
?
void?Coding()??
{??
????//如果只有一個節點編碼會出錯~??
cout<????char?s[100];??
cin>>s;
????if?(!freopen(s?“r“?stdin))
{??
cout<<“你輸入的文件\““<????????return;??
????}??
?????
????strcat(s?“.zdker“);??
cout<<“已經成功壓縮到:“<????freopen(s?“w“?stdout);??
?????
????//統計??
????int?i?len?=?2?*?RANGE?-?1; //RANGE=256最大也就是256
????node?*ht?=?(node?*)malloc(sizeof(node)?*?len);??
????node?temp?=?{?0?0?0?0?NULL?};??
????for?(i=0;?i {
????????ht[i]?=?temp;??
????}??
????while?((i?=?getchar())?!=?EOF) //頻度分析???
{??
????????ht[i].w++;??
????}??
?????
????//建樹??
????int?Select(node?*?int?int?*?int?*);??
????int?s1?s2;??
????for?(i=RANGE;?Select(ht?i?-?1?&s1?&s2);?i++)
{??
????????ht[s1].p?=?ht[s2].p?=?i;??
????????ht[i].l?=?s1;??
????????ht[i].r?=?s2;??
????????ht[i].w?=?ht[s1].w?+?ht[s2].w;??
????}??
?????
????//找出編碼??
????char?temps[RANGE]; //256
????int?start?now?c;??
????temps[RANGE?-?1]?=?0; //最后一個先放個0
????for?(i=0;?i {??
????????if?(ht[i].w) //是否有字符
{???
????????????start?=?RANGE?-?1; //第二次還是從最后一個開始
????????????now?=?i;???
????????????while?(c?=?ht[now].p) //不是根結點
{???
????????????????if?(ht[c].l?==?now)?
{???
????????????????????temps[--start]?=?‘0‘;???
????????????????}???
????????????????else?
{???
????????????????????temps[--start]?=?‘1‘;???
????????????????}???
????????????????now?=?c;???
????????????}???
????????????ht[i].cd?=?(char?*)malloc((RANGE?-?start)?*?sizeof(char));//temps中有RANGE?-?start個已賦值后面開始
????????????strcpy(ht[i].cd?&temps[start]);???
??????

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????26112??2007-09-13?01:42??哈夫曼問題\2.1??軟件需求分析.doc

?????文件??????25088??2007-09-13?01:46??哈夫曼問題\2.2??概要設計.doc

?????文件?????147456??2007-09-13?01:45??哈夫曼問題\2.3??詳細設計.doc

?????文件??????49152??2007-09-13?01:47??哈夫曼問題\2.4??測試分析及用戶使用手冊.doc

?????文件???????6532??2007-09-12?12:21??哈夫曼問題\哈夫曼壓縮與解壓?.cpp

?????文件???????3535??2007-09-13?22:16??哈夫曼問題\哈夫曼壓縮與解壓?.dsp

?????文件????????559??2007-09-13?22:16??哈夫曼問題\哈夫曼壓縮與解壓?.dsw

?????文件??????41984??2007-09-13?22:16??哈夫曼問題\哈夫曼壓縮與解壓?.ncb

?????文件??????48640??2007-09-13?22:16??哈夫曼問題\哈夫曼壓縮與解壓?.opt

?????文件????????268??2007-09-13?22:16??哈夫曼問題\哈夫曼壓縮與解壓?.plg

?????文件??????51200??2007-09-13?02:44??哈夫曼問題\附:源代碼.doc

?????目錄??????????0??2009-06-26?18:18??哈夫曼問題

-----------?---------??----------?-----??----

???????????????400526????????????????????12


評論

共有 條評論