哈夫曼树与哈夫曼码

来源:百度知道 编辑:UC知道 时间:2024/05/26 15:24:32
输入任意一个大型文本,统计各字符出现的频度,输出结果;
使用顺序表或二叉链表或三叉链表作存储结构,构造哈夫曼
树;
确定和输出各字符的哈夫曼码。

跪求程序代码 要交报告了 求高手做下2个题目
邮箱38464478@qq.com

哈夫曼树

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXNODE 100
#define MAXNUM 50
#define MAXINT 60000

char hc[MAXNUM-1][MAXNUM];

typedef struct HtNode
{
int weight;
int parent, lchild, rchild;
}HtNode;

typedef struct HtTree
{
struct HtNode ht[MAXNODE+1];
int root;
}HtTree, *PHtTree;

void Select (PHtTree pht, int pos, int *x1, int *x2)
{
int j;
int m1 = MAXINT, m2 = MAXINT;
for (j=1; j<pos; j++)
{
if (pht->ht[j].weight<=m1 && pht->ht[j].parent == 0)
{
m2 = m1;
*x2 = *x1;
m1 = pht->ht[j].weight;
*x1 = j;
}
else if (pht->ht[j].weight<m2 && pht->ht[j].parent == 0)
{
m2 = pht->ht[j].weight;
*x2 = j;
}
}
}

PHt