建立哈夫曼树,计算树的带权路径。
#include <iostream>
#include <queue>
#include <malloc.h>
using namespace std;
typedef struct HTNode
{
int weight, parent, lchild, rchild;
int flag;
friend bool operator <(HTNode a, HTNode b)
{
if (a.weight!=b.weight)
return a.weight > b.weight;
return a.flag > b.flag;
}
}HTNode, *HuffmanTree;
typedef char **HuffmanCode;
int CreatTree(HuffmanTree &HT, int n)//构建哈夫曼树
{
int i, m;
m = 2 * n - 1;
Huff......
阅读全文