哈夫曼樹的實(shí)現(xiàn)
WPL計(jì)算的遞歸實(shí)現(xiàn):
WPL:所有葉節(jié)點(diǎn)帶權(quán)路徑長(zhǎng)度之和
//計(jì)算WPL终佛,可以采用層序遍歷,也可以用隨便一種遍歷方式的雾家,但是要傳遞該節(jié)點(diǎn)所在的層次
static int WPL = 0;
void GetWPL(BiTree Tree,int Deep=0)
{
if (Tree!=NULL)
{
//對(duì)葉子節(jié)點(diǎn)進(jìn)行計(jì)算
if ((Tree->lchild==NULL)&&(Tree->rchild==NULL))
{
WPL += (Tree->data)*Deep;
}
GetWPL(Tree->lchild,Deep+1);
GetWPL(Tree->rchild,Deep+1);
}
}
本來(lái)想用堆來(lái)實(shí)現(xiàn)哈夫曼樹的簡(jiǎn)歷的铃彰,一路下來(lái)發(fā)現(xiàn)有點(diǎn)麻煩,有空再出來(lái)寫芯咧,考研要緊牙捉。
http://www.cnblogs.com/skywang12345/p/3706370.html