谁帮我找找错误---c语言赫夫曼树程序

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:44:09
#include"stdio.h"
#include "conio.h"
#include "string.h"
#define ERROR 0
#define OVERFLOW -2

typedef struct
{
unsigned int weight;
unsigned int parent,lchild,rchild;
}HTNode,*HuffmanTree;
typedef char ** HuffmanCode;
HuffmanCode HC; /*指针数组存放赫夫曼编码*/

HuffmanCoding(int *w,int n)
{
int m,i,c,start,f;
int s1,s2;
int *p1=&s1;
int *p2=&s2;
char *cd;
HuffmanTree HT;
HuffmanTree p;
if(n<=1) return ERROR;
m=2*n-1;
HT=(HuffmanTree)malloc((m+1)*sizeof(HTNode));
for(p=HT,i=1;i<=n;++i,++p,++w)
{
p->weight=*w;
p->parent=p->lchild=p->rchild=0;
}
for(;i<=m;++i,++p)
{
p->weight=0;
p->parent=p->lchild=p->rchild=0;
}
for(i=n+1;i<=n;++i)
{

我之前也做了一个,可以对字母进行编码译码,你参考参考下~~~~

#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=-1;