设HUFFMan树已采用二叉链表存储结构,求树的带权路径长度(WPL)的算法如下,其中ht为树的根结点的指针,S为指针类型的栈,clearstack(S),push(S,p),pop(S),emptystack(S)分别为置栈空,指针P进栈,出栈,判栈是否空的函数
typedef float weight;
typedef struct hnode
{ weight w;
struct hnode *Lchild,*Rchild;
}hnode,*htptr;
weight HWPL(htpt ht)
{ htptr p;
stype S;
weight cpwl;
___(1)____;
if(ht==null)
return(cwpl);
clearstack(S);
___(2)___;
while(p||!emptystack(S))
{
while(___(3)____)
{
push(S,p);
___(4)___;
}
p=pop(S);
if(___(5)___)
___(6)___;
___(7)___;
}
___(8)___;
} |