#include<stdio.h>
#include<stdlib.h>#include<string.h>
#include<conio.h>
#define MAXVALUE 200 /*权值的最大值*/
#define MAXBIT 30 /*最大的编码位数*/
#define MAXNODE 30 /*初始的最大的结点数*/
struct haffnode
{
char data;
int weight;
int flag;
int parent; /*双亲结点的下标*/
int leftchild; /*左孩子下标*/
int rightchild; /*右孩子下标*/
};
struct haffcode
{
int bit[MAXNODE];
int start; /*编码的起始下标*/
char data;
int weight; /*字符权值*/
};
/*函数说明*/
/************************************************************************/
void pprintf(struct haffcode haffcode[], int n);
/*输出函数*/
void haffmantree(int weight[], int n, struct haffnode hafftree[], char data[]);
/*建立哈夫曼树*/
void haffmancode(struct haffnode hafftree[], int n, struct haffcode haffcode[]);
/*求哈夫曼编码*/
/************************************************************************/
void haffmantree(int weight[], int n, struct haffnode hafftree[], char data[])
/*建立叶结点个数为n,权值数组为weight[]的哈夫曼树*/
{
int i, j, m1, m2, x1, x2;
/*哈夫曼树hafftree[]初始化,n个叶结点共有2n-1个结点*/
for(i = 0; i &