高分求霍夫曼,急啊,下午就要交了,

来源:百度知道 编辑:UC知道 时间:2024/05/25 18:54:07
下面是这个要求,急求啊,我在线等啊,下午4点要交,所以我希望能2点前把这个东西搞定啊,谢谢了啊
利用哈夫曼编码进行通信可以大大提高信道利用率,缩短信息传输时间,降低传输成本。这要求在发送端通过一个编码系统对待传输预先编码,在接收端将传来的数据进行译码。对于双工通道(即可以双向传输信息的信道),每端都需要一个完整的编/译码系统。试为这样的信息收发站编写一个哈夫曼码的编/译码系统。
百度知道的分数我不在意,只要你们能帮我解决掉,给多少分都无所谓(我一共只有360分)还有我是在C-FREE3.5上运行的,如果有错误的就算了,

#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<iostream.h>
typedef struct{
int weight;
int parent,lchild,rchild;
}htnode,*huffmantree;
typedef char **huffmancode;

void select(huffmantree ht,int n,int &s1,int &s2){
int i,flag;
for(i=1,flag=1;i<=n;i++){
if(ht[i].parent==0){
if(flag==1){
s1=i; flag=0;
}
else if(ht[i].weight<ht[s1].weight) s1=i;
}
}
for(i=1,flag=1;i<=n;i++){
if((ht[i].parent==0)&&(i!=s1)){
if(flag==1){
s2=i; flag=0;
}
else if(ht[i].weight<ht[s2].weight) s2=i;
}
}
}

void initialization(huffmantree &ht,huffmancode &hc,int *&w,int &n,char *&ch){
//数组huffmantree huffmancode中不用0号单元
//建huffmantree
//同双亲的两棵子树,小的在左边,大的在右边
int m,i,s1,s2,start,c,f,*q;
char a,*cd,*t;
huffmantree p;