哈夫曼树的一些问题

来源:百度知道 编辑:UC知道 时间:2024/06/21 09:56:00
我的程序有些错误,而且错误都是一个类的,不知道怎么修改,请高手帮忙看看,有追加,只要帮我解决问题了,追加50-100吧

问题太长了,所以只好这样了http://hi.baidu.com/%B5%FB%C6%C6%D1%E6%B3%BA/blog/item/bf294038d8cbd423b9998f41.html

结构定义错误。

//这是我以前做的,附带对字母的编码译码,你可以参考参考

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct htnode
{
int ww,parent,llink,rlink;
char cc,buffer[20]; //cc用来存放字母,buffer用来存放编码字符
}datatype;

struct httree
{
int m;
datatype * ht;
};
typedef struct httree * phttree;

phttree creatht(int m,char * n,int * w)
{
phttree pht;
int x1,x2,m1,m2;
pht=(phttree)malloc(sizeof(struct httree));
if(pht==NULL)
{
printf("申请空间失败!!\n");
return pht;
}
pht->m=m;
pht->ht=(datatype *)malloc(sizeof(datatype)*(2*m-1));
for(int i=0;i<2*m-1;i++)
{
pht->ht[i].llink=-1;
pht->ht[i].rlink=-1;
pht->ht[i].parent=-1;
if(i<m)
{
pht->ht[i].ww=w[i];
pht->ht[i].cc=n[i];
}
else
{
pht->ht[i].ww=-