Loading

Java通过PriorityQueue构建大顶堆和小顶堆

Comparator<Object> comparator = Comparator.comparing(Obj::getValue);

小顶堆:

PriorityQueue minHeap = new PriorityQueue(comparator);

大顶堆:

PriorityQueue maxHeap = new PriorityQueue(comparator.reversed());

Top N 问题,应该使用有界堆,基于PriorityQueue实现UnboundedPriorityQueue,HuTool已有实现

^_^

posted @ 2021-08-09 20:56  dai.sp  阅读(319)  评论(0编辑  收藏  举报