Is there a PriorityQueue implementation with fixed capacity and custom comparator?

后端 未结 9 2513
后悔当初
后悔当初 2020-11-28 05:59

Related questions:

  • Java PriorityQueue with fixed size
  • How do I use a PriorityQueue?
  • get indexes of n smallest elements in an array
9条回答
  •  佛祖请我去吃肉
    2020-11-28 06:50

    I can't think of a ready-to-use one, but you can check my implementation of this collection with similar requirements.

    The difference is the comparator, but if you extend from PriorityQueue you'll have it. And on each addition check if you haven't reached the limit, and if you have - drop the last item.

提交回复
热议问题