上传者: edmund_g
|
上传时间: 2022-01-11 22:23:35
|
文件大小: 4KB
|
文件类型: -
//Date:2011.11
# include
# include
# include
# define N 1000
typedef struct//Huffman树节点类型及相关定义
{
unsigned int weight,parent,lchild,rchild;
}HTnode, *HuffmanTree;
typedef char * * HuffmanCode;//字符对应的编码序列链
HuffmanTree HT;//全局变量声明(Huffman树和编码列类型声明)
HuffmanCode HC;
void createH (int * w,int n)//根据所给的字符序列创建Huffman树
{
int m,i,s1,s2;
m=2*n-1;
HT=(HuffmanTree)malloc((m+1)*sizeof(HTnode));
for(i=1;i<=n;i++)
{
HT[i].weight=w[i-1];
HT[i].parent=0;
HT[i].lchild=0;
HT[i].rchild=0;