这个题主要考察的是对haffman树的解法。先给出代码,因为其中还有点小错误,但是影响不大。
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct HuffmanNode
{
unsigned int weight;
int parent,lchild,rchild;
}HuffmanNode,*HuffmanTree;
typedef char ** HuffmanCode;
char *count(char *input,int *temp)
{//统计单个字母出现的顺序
int i;
int len=strlen(input);
int hash[256]={0};
int count=0;
for(i=0;i<len;i++)
{
hash[input[i]]++;
}
for(i=0;i<256;i++)//统计出现的字符个数
{
if(hash[i])
count++;
}
char *output=(char*)malloc(count+1);
count=0;
for(i=0;i<256;i++) //存储出现的字符
{
if(hash[i]!=0)
{
output[count++]=i;
*temp=hash[i];
temp++;
}
}
output[count]='\0';
return output;
}
int min(HuffmanTree *HT,int n)
{//找到其中最小的一个
int i=0;
unsigned int k=1000;
int flag;
while((*HT)[i].parent!=0)
i&#