PriorityQueue/Heap Update

前端 未结 6 717
礼貌的吻别
礼貌的吻别 2020-12-05 07:07

Does Java have an easy way to reevaluate a heap once the priority of an object in a PriorityQueue has changed? I can\'t find any sign of it in Javadoc, but the

6条回答
  •  渐次进展
    2020-12-05 07:27

    The standard interfaces don't provide an update capability. You have use a custom type that implements this.

    And you're right; although the big-O complexity of algorithms that use a heap doesn't change when you remove and replace the top of the heap, their actual run time can nearly double. I'd like to see better built-in support for a peek() and update() style of heap usage.

提交回复
热议问题