huffman.h

来自「自己做的数据结构实验题(合并链表」· C头文件 代码 · 共 55 行

H
55
字号
#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 + =
减小字号Ctrl + -
显示快捷键?