📄 huffman.h
字号:
#include <vector>
#include <queue>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct huffman_node;
typedef huffman_node *node_ptr;
typedef int Type;//用于记录解码还是编码
struct huffman_node{
char id;
int freq;
string code;
node_ptr left,
right,
parent;
};
static const int MAX_SIZE = 256;
class huffman{
public:
class compare{
public:
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,Type T);//根据路径初始化
void create_pq();//创建优先队列 用于构建二叉树
void create_huffman_tree();//创建huffman tree
void calculate_huffman_codes();//编码
void create_node_array();
void save_to_file();//保存编码
void RunHuffman();
node_ptr node_array[MAX_SIZE];
void RunHuffmanReverse();
void create_huffman_tree2();
private:
priority_queue<node_ptr,vector<node_ptr>,compare> pq;
ifstream in_file;
ofstream out_file;
string in_file_name;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -