标题:CreateHuffmanTree中调用的三个函数:InputWeight,SelecMin和InitHuffmanTr ...
取消只看楼主
glorycwr
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-11-30
 问题点数:0 回复次数:0 
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;
    }
         }
搜索更多相关主题的帖子: InputWeight SelecMin 函数 
2008-11-30 22:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-247097-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.342579 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved