⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 huffmantree.h

📁 使用霍夫曼huffman 編碼方式 對文件進行壓縮 程序很簡單 主要是幫助新人了解霍夫曼編碼的實現方法
💻 H
字号:
#include <stdio.h>
static const bool LEFT=true,RIGHT=false;
struct huffmancode
       {
               char chr;
               bool *code;
               int length; 
               huffmancode *pre,*left,*right;         
       };
struct str_char
       {
               unsigned int frequency;
               char chr;
       };
struct nodes
       {
               str_char key;
               nodes * pre,*left,*right;
       };
struct nodeslist
       {
                nodes *node;
                nodeslist * next;
       };

class huffmantree
{      
       public:
           huffmantree();//yes
           ~huffmantree();//yes
           void Insertbyfre(str_char &key);//yes
           void Insertbychr(char chr);
           void printall();
           int getnodes();//yes
           int freeall();//yes
           bool treetoarray(str_char * &arr,int & size);
           bool makeHufftree(str_char * ordarr,int size);
           bool getchr(bool code,char & chr);
           //---------------------------------------------------------------
           bool codes_get(char chr,bool *&code,int &length);
           bool codes_makeCodestree();
           void codes_printall();
           unsigned long WEP;
       protected:
           nodes * decode_node;
           nodes * tree;
           huffmancode *codestree;
           void inordprint(nodes * root);
           void countnodes(nodes * root,int & sum);//yes
           void fillarray(str_char * &arr,int & index,nodes * root);
           nodes * newElem();
           bool ifleaf(nodes * node);
           //------------------------------------------------------
           void freeallcodes(huffmancode * root,int &sum);
           int  codes_freeall();
           void codes_Insertbychr(char chr,bool *code,int length);
           void getcodes(char chr,bool *&code,int &length,huffmancode * root);
           void makeCodestree(nodes * root,int path,unsigned long &WEP);
           void codes_inordprint(huffmancode * root);
}
;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -