1.根据哈夫曼编码原理,编写一个在用户输入结点权值的基础上建立的哈夫曼编码的程序。

来源:百度知道 编辑:UC知道 时间:2024/06/24 15:05:12
用数据结构C语言编程

这个是我同学的哈夫曼编码程序

另外还有解码的程序,要的话再商量

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

#define TRUE 1
#define ERROR 0
#define OK 1
#define FALSE 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define Status int
#define MAXLENGTH 128

typedef struct HTnode
{
long weight;
int parent;
int lchild;
int rchild;
}HTNode, *HuffmanTree;

typedef struct CTnode
{
long weight;
char *coded_string;
}CharacterTable;

typedef char * *HuffmanCode;
FILE *fp=NULL;

void Analyse (CharacterTable * *character_table, long * *w, char * *chara, int &n)//分析所有不同的字符的权值
{
long *tmpw;
char ch, *tmpchara;
int i;
(*character_table)=(CharacterTable *)malloc(128*sizeof(CharacterTable));//定义存放字母的数组
for(i=0; i<128; i++)
{
(*character_table)[i].weight=0; //初始化
(*ch