哈夫曼編碼和解碼

2021-10-02 16:34:18 字數 1200 閱讀 1529

試題描述:輸入為:一段英文或中文的文章(原文),對輸入的文章構造哈夫曼樹,生成對應的編碼,輸出為:原文所對應的編碼(譯文),根據已經生成的編碼表,輸入任意的譯文可以得到對應的原文。要求有執行結果截圖。

#include

using

namespace std;

typedef

struct point

huf;

typedef

struct nodetree;

tree createheap()

tree insertheap

(tree tmp,huf node)

tmp.array[t]

=node;

return tmp;

}huf getmin

(tree tmp)

tree deleteheap

(tree tmp)

tmp.array[i]

=element;

return tmp;

}void

encode

(vector huffman,

char c)

}while

(tmp.parent!=-1

)while

(!q.

empty()

)}void

decode

(vector huffman,string c)

else

if(c[i]

=='0')if

(tmp.left==-1

)}}int

main

(int argc,

char

const

*ar**)

while

(minheap.size!=2)

cout<"編碼已完成!"

int i =

0; i < article.

length()

;++i)

cout<"請輸入需要解碼的文字"

(cin,article)

; cout<<

"解碼完成!"

(huffman,article)

;return0;

}

哈夫曼編碼解碼

簡單實現編碼解碼功能 列印哈夫曼樹形 該怎麼做呢 求教!實現初始化,建立huffman樹,並完成字元的編碼 之前解碼用for迴圈不能夠重新復位遍歷 while更好用 include stdio.h include string.h define n 10 待編碼字元的個數,即樹中葉結點的最大個數 d...

哈夫曼編碼與解碼

include include include include define maxnum 60typedef struct huffnode typedef struct huffcode huffnode ht maxnum 2 存放哈夫曼樹 huffcode hcd maxnum 存放ht陣列...

電文編碼解碼 哈夫曼編碼

幫別人改 原 只能輸入定義好輸入字元個數 輸入的字元及每個字元的權重,來生成對應的哈夫曼輸和哈夫曼編碼,以及對應的解碼功能,在原 基礎是修改,能夠根據使用者輸入的字串,計算每個字元的權重,然後生成對應的編碼。temp i 標記陣列儲存末位位置 i 1 printf 輸出哈夫曼解碼 n typedef...