#include <iostream>
#include<string>
using namespace std;
class HuffNode
{
public:
char c; // 结点的字符
int weight; // 权值
int parent, lChild, rChild; // 左右孩子指针
};
class CodeNode
{
public:
char* code;
int length;
};
class HuffTree
{
private:
int Node_cnt=0;
HuffNode* huff=NULL;
CodeNode* HuffCode= NULL;
public:
HuffTree(int n, char* c, int* weights); // 创建Huffman树
~HuffTree(); // 析构函数
void setNode_cnt(int cnt){ Node_cnt = cnt; }
void select(int end, int& index1, int& index2); // 选出最小和次小叶子结点
void printHuffTree();
void setHuffCode();
void decoding();// 根据Huffman编码解析字符串
void printHuffCode();
int getNode_cnt(){ return Node_cnt; }
};
HuffTree::~HuffTree()
{
delete[] huff;
delete[] HuffCode;
}
void HuffTree::printHuffCode()
{
c++实现求哈夫曼数及其对应的哈夫曼编码和译码
最新推荐文章于 2019-12-31 20:05:53 发布