我的首发平台是公众号【CodeAllen】,学习交流QQ群:736386324,转载请注明出处
赫夫曼当初主要是为了解决远距离通信的数据传输最优化问题
基本学校都是要求只要知道基本原理就可以
赫夫曼编码可以非常有效的压缩数据:通常可以节约20%到90%的空间
名词解释:定长编码,变长编码,前缀码 定长编码:像ASCII编码 变长编码:单个编码的长度不一致,可以根据整体出现频率来调节 前缀码:所谓的前缀码,就是没有任何码字是其他码字的前缀
基本的过程: build a priority queue //从小到大的顺序 build a huffmanTree build a huffmanTable encode decode
main.c
#include
#include
#include "huffman.h"
int main(void)
{
//We build the tree depending on the string
htTree *codeTree = buildTree("beep boop beer!");
//We build the table depending on the Huffman tree
hlTable *codeTable = buildTable(codeTree);
//We encode using the Huffman table
encode(codeTable,"beep boop beer!");
//We decode using the Huffman tree
//We can decode string that only use symbols from the initial string
decode(codeTree,"0011111000111");
//Output : 0011 1110 1011 0001 0010 1010 1100 1111 1000 1001
return 0;
}