CreateHuffmanTree中调用的三个函数:InputWeight,SelecMin和InitHuffmanTree.
CreateHuffmanTree中调用的三个函数:InputWeight,SelecMin和InitHuffmanTree.① 初始化
InitHuffmanTree(HuffmanTree T)
{ int i;
for(i=0;i<m;i++)
{T[i]->parent=-1;
T[i]->lchild=-1;
T[i]->rchild=-1;
T[i]->weigh=0;
}
}
② 读入叶子结点权值
InputWeigh(HuffmanTree T)
{ int I;
for(i=0;i<n;i++)
scanf(“%d”,&T[i]->weigh);
}
③ 选出两个权至最小的根结点
SelecMin(HuffmanTree T,i-1,&p1,&p2)
int i,p1,p2;
{ int j,small1,small2;
small1=small2=max; /*设max为整型最大值*/
for(j=0;j<i-1;j++)
if(T[j]->parent==-1)
if(T[j]->weigh<small1)
{small2=small1; /*改变最小权、次小权及对应位置*/
small1=t[j]->weigh;
p2=p1;
p1=j;
}
else
if(T[j]->weigh<small2)
{small2=T[j]->weigh; /*改变最小权及对应位置*/
p2=j;
}
}