0

我用这样的入队方法创建了一个独特的优先级队列:

huzz.ak.UniquePriorityQueue.prototype.enqueue =
    function(priority, value) {
  var node = {'valid': true, 'value': value, 'priority': priority};
  var key = value.key;
  if (this.pointers_[key] !== undefined) {
    this.pointers_[key].valid = false;
  }
  this.pointers_[key] = node;
  this.priorityQueue_.enqueue(priority, node);
};

当我输出值时,它们以随机顺序出现:

while (true) {
  p = this.priorityQueue_.dequeue();
  this.logger_.log(p.priority + ' ' + p.value.toString() + ' ' + p.valid);
}

1265 ... true

1413 S..N. false

1265 ... false

92 S..N. true

1734 .........E false

59 ... false

75 ...B false

92 S..N. false

为什么队列不按预期顺序(从小到大)返回值。

谢谢!

4

1 回答 1

0

事实证明,在我的部分代码中,我传递了一个列表而不是列表的长度,这搞砸了一切。我修复了这个错误,优先队列按预期工作!

于 2012-11-07T02:52:45.397 回答