有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    PriorityQueue有以下主要方法:

    • 添加(e)/报价(e)-将元素e添加到队列:O(日志(n))
    • peek()-获取排序队列的第一个元素:O(1)
    • pool()-获取排序队列的第一个元素,并将其从队列中移除:O(log(n))
    • 删除(e)-从列表O(日志(n))中删除元素e
    • 包含-检查队列是否包含元素e:O(n)

    其中n表示队列中的元素数

  2. # 2 楼答案

    然后读the documentation

    Implementation note: this implementation provides O(log(n)) time for the enqueing and dequeing methods (offer, poll, remove() and add); linear time for the remove(Object) and contains(Object) methods; and constant time for the retrieval methods (peek, element, and size).