Java implementation for Min-Max Heap?

前端 未结 5 1168
遥遥无期
遥遥无期 2020-12-02 09:00

Do you know of a popular library (Apache, Google, etc, collections) which has a reliable Java implementation for a min-max heap, that is a heap which allows to peek its mini

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 09:20

    Instead of a max-min heap, could you use two instances of a java.util.PriorityQueue containing the same elements? The first instance would be passed a comparator which puts the maximum at the head, and the second instance would use a comparator which puts the minimum at the head.

    The downside is that add, delete, etc would have to be performed on both structures, but it should satisfy your requirements.

提交回复
热议问题