#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define n 8 //叶子数目
#define m 2*n-1 //树中结点总数
typedef struct {
//结点类型
double weight; //结点的权值
int parent, lchild, rchild;//双亲指针及左右孩子
}HTNode;
typedef HTNode HuffmanTree[m];//HuffmanTree是向量类型
typedef struct {
//用于SelectMin函数中排序的结点类型
int id; //保存根结点在向量中的序号
double weight; //保存根结点的权值
}temp;
typedef struct {
//编码结点
char ch; //存储字符
char bits[n + 1]; //存放编码位串
}CodeNode;
typedef CodeNode HuffmanCode[n];
void InitHuffmanTree(HuffmanTree T) {
//初始化哈夫曼树
//将2n-1个结点里的三个指针均置为空(即置为-1),权值置为0
for (int i = 0; i < m; i++) {
T[i].lchild = -1;
T[i].rchild = -1;
T[i].parent = -1;
T[i].weight =
最优前缀编码
最新推荐文章于 2022-11-25 19:50:32 发布