h1.h
来自「自己做的数据结构实验题(合并链表」· C头文件 代码 · 共 46 行
H
46 行
#include <vector>
#include <queue>
#include <iostream>
#include <string>
class huffman{
public:
class compare{
public:
struct huffman_node;
typedef huffman_node *node_ptr;
struct huffman_node{
char id;
int freq;
string code;
node_ptr left,
right,
parent;
};
bool operator()(const node_ptr& c1,const node_ptr& c2)const{
return (*c1).freq>(*c2).freq;
}
};
huffman(string in_file_name,string out_file_name);//根据路径初始化
void create_pq();//创建优先队列 用于构建二叉树
void create_huffman_tree();//创建huffman tree
void calculate_huffman_codes();//编码
void save_to_file();//保存编码
static const int MAX_SIZE=256;
node_ptr node_array[MAX_SIZE];
private:
priority_queue<node_ptr,vector<node_ptr>,compare> pq;
fstream in_file,
out_file;
string in_file_name;
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?