哈夫曼编码
1 2 3 4 5 6 7 8 9 10
//定义结构体
//节点
typedef struct
{
double weight;//权重
int parent;//父节点
int lchild;//左孩子节点
int rchild;//右孩子节点
char value;//节点代表的字符
}hufcode;
//编码
typedef struct
{
int start;
int bit[10];
}hufbitt;
完整代码
#include<iostream>
#define MAXCODE 200
#define MAXbit 100
using namespace std;
//节点
typedef struct
{
double weight;//权重
int parent;//父节点
int lchild;//左孩子节点
int rchild;//右孩子节点
char value;//节点代表的字符
}hufcode;
typedef struct
{
int start;
int bit[10];
}hufbitt;
hufcode hujd[MAXCODE];
hufbitt hufbit[MAXbit];
//初始化节点,parent,lchild,rchild=-1,weight=0
void initcode()