这是我的代码:
private HuffmanNode buildTree(Map<String, Double> map) {
Queue<HuffmanNode> newQueue = createNodeQueue(map);
int checkD = (newQueue.size() - d) / (d - 1);
double n = d + checkD*(d - checkD);
while(newQueue.size() > d - 1){
HuffmanNode[] newArray = new HuffmanNode[d];
double probCounter = 0;
for(int i = 0; i < d; i++){
newArray[i] = newQueue.remove();
probCounter += newArray[i].probability;
}
HuffmanNode newHuffman = new HuffmanNode(null, probCounter, newArray);
if (n == newQueue.size()){
newQueue.add(new HuffmanNode("dummy", 0, null));
}else{
newQueue.add(newHuffman);
}
}
return newQueue.remove();
}
我正在尝试编写一个采用整数D> 2的Dary Huffman树程序。目前,我的函数似乎仅在整数为2时才起作用。我试图让我的函数添加一个虚拟对象节点进入队列,它似乎不起作用。