2
값에 따라 해시 맵을 정렬하려고한다고 가정합니다. 이를 위해 비교 자로 priorityQueue를 구현합니다. 결과적으로 결과 pq는 인덱스 0에서 끝까지 최대 값에서 최소값 순으로 정렬됩니다.Maxheap 대 priorityqueue 혼란
PriorityQueue<Map.Entry<Integer, Integer>> pq = new PriorityQueue<Map.Entry<Integer, Integer>>(
new Comparator<Map.Entry<Integer, Integer>>() {
@Override
public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) {
return o2.getValue() - o1.getValue();
}
});
그러나, 누군가가 내가 힙 아동 값보다 단지 부모 값이 큰 것을 이해하지만 maxheap 그것을 왜 내가 이해할 수없는, 그것은 maxheap이라고 말했다 : 여기
코드인가? priorityQueue에 비교기를 구현하는 것 뿐인가요? 이것은 힙과 어떤 관련이 있습니까?