Java的PriorityQueue与min-heap有何不同? [英] How does Java's PriorityQueue differ from a min-heap?

查看:163
本文介绍了Java的PriorityQueue与min-heap有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你不能 insertWithPriority ,他们为什么要命名 PriorityQueue ?它看起来非常类似于堆。有什么不同吗?如果没有区别,那么为什么它被命名为 PriorityQueue 而不是Heap?

Why did they name PriorityQueue if you can't insertWithPriority? It seems very similar to a heap. Are there any differences? If no difference, then why was it named PriorityQueue and not Heap?

推荐答案

Add()的工作方式类似于insertWithPriority。

Add() works like an insertWithPriority.

您可以使用构造函数定义所需类型的优先级:

You can define priority for the type that you want using the constructor:

PriorityQueue(int, java.util.Comparator)

http://download.oracle下查看.com / javase / 1,5.0 / docs / api / java / util / PriorityQueue.html

比较者给出的顺序代表了排队。

The order the Comparator gives will represent the priority in the queue.

这篇关于Java的PriorityQueue与min-heap有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆