哈夫曼树的编码与译码;
任意输入一段字符串对其进行编码与译码。
在计数这里用一个结构体数组,我觉得这样定义在对哈夫曼树赋值时比较方便,但是有同学问有没有更好方法,暂时没有想出来。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n;
int m;
int l;
int x;
char h[100];
char g[100];
char v[100];
struct tree
{
char a;
int weight;
int parent;
int Lchild;
int Rchild;
}ht[];
struct coder
{
int data;
char code[10];
}hc[];
struct str
{
char s;
int r;
}b[100];
void select(struct tree ht[],int k,int *s1,int *s2)
{
int i;
for(i=1; i<=k ; ++i)
{
if(ht[i].parent == 0)
break;
}
*s1 = i;
for(i=1; i<=k; ++i)
{
if(ht[i].parent==0 && ht[i].weight<ht[*s1].weight)
*s1 = i;
}
for(i=1; i<=k; ++i)
{
if(ht[i].parent==0 && i!=*s1)