How does Java's PriorityQueue differ from a min-heap?

前端 未结 6 1983
时光取名叫无心
时光取名叫无心 2021-01-30 00:44

Why did they name PriorityQueue if you can\'t insertWithPriority? It seems very similar to a heap. Are there any differences? If no difference, the

6条回答
  •  既然无缘
    2021-01-30 01:23

    For max-heap you can use:

    PriorityQueue queue = new PriorityQueue<>(10, Collections.reverseOrder());
    

提交回复
热议问题