最方便建立网站,北京定制网络营销收费,在线设计自己的签名免费,杭州营销网站建设平台本文章所需要的内容需要自行准备一个名为input.txt的文本文件作为案例演示。内容选择英语小短文即可
第一步,建立哈夫曼数
#include iostream
#include fstream
#include queue
#include vector
#include stringusing namespace st…本文章所需要的内容需要自行准备一个名为input.txt的文本文件作为案例演示。内容选择英语小短文即可
第一步,建立哈夫曼数
#include iostream
#include fstream
#include queue
#include vector
#include stringusing namespace std;typedef struct
{unsigned char charname; //出现的字符是谁unsigned int charnumber; //出现的频率
}CharNode;static bool open_input_file(ifstream input , const char *inputFileName)
{input.open(inputFileName);if(!input.is_open()){return false;}return true;
}//定义哈夫曼树结点
struct MinHeapNode
{char data;unsigned int freq; //权值MinHeapNode *left, *right;MinHeapNode(char data , unsigned freq){left = right = nullptr;this-data = data;this-freq = freq;}
};
typedef struct MinHeapNode MinHeapNode;struct compare
{bool operator()(MinHeapNode* l , MinHeapNode* r){return (l-freq r-freq);}
};static void get_huffman_code(MinH