/**
* 使用优先队列构建哈弗曼树
*/
public void createTree(){
//优先队列
PriorityQueue nodeQueue = new PriorityQueue();

//把所有的节点都加入到 队列里面去
for (int i=0;i<256;i++){
if(byteCount[i]!=0){
hfmNode node = new hfmNode(i,byteCount[i]);
nodeQueue.add(node);//加入节点
}
}
//构建哈弗曼树
while(nodeQueue.size()>1)
{
hfmNode min1 = nodeQueue.poll();//获取队列头
hfmNode min2 = nodeQueue.poll();

hfmNode result = new hfmNode(0,min1.times+min2.times);
result.lChild=min1;
result.rChild=min2;
nodeQueue.add(result);//加入合并节点
}
root=nodeQueue.peek(); //得到根节点
}



http://www.cppblog.com/biao/archive/2011/08/13/135457.html