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已有实现
^_^