您当前的位置: 首页 >  数据结构
  • 2浏览

    0关注

    880博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【大话数据结构C语言】35 赫夫曼编码及其C语言实现

CodeAllen嵌入式编程 发布时间:2021-04-10 00:14:52 ,浏览量:2

我的首发平台是公众号【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;
}
关注
打赏
1665938897
查看更多评论
立即登录/注册

微信扫码登录

0.0420s