作业帮 > 综合 > 作业

给定权值40,30,15,5,4,3,3,构造相应的哈夫曼树及其编码.

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/05/06 10:23:13
给定权值40,30,15,5,4,3,3,构造相应的哈夫曼树及其编码.
给定权值40,30,15,5,4,3,3,构造相应的哈夫曼树及其编码.
以下是我做个的类似的题的代码:
#include
#include
#include
#include
#include
usingnamespace std;
typedefstruct{ //哈夫曼树的结构体
char ch;
int weight; //权值
int parent,lchild,rchild;
}hnode,*hfmtree;
typedefchar **hfmcode;

void Select(hfmtree &TREE,inta,int *p1,int *p2) //Select函数,选出TREE树到a为止,权值最小且parent为0的2个节点
{
int i,j,x,y;
for(j=1;j