Interface PQueue<E>

All Known Implementing Classes:
SlowPQueue

public interface PQueue<E>
A priority queue containing distinct elements of type E, with priorities represented as values of type double. Smaller values expressing higher priorities; for example, 0.0 means higher priority than 1.0 does. Below, N is used as the number of elements currently in the priority queue.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(E e, double priority)
    Effect: Add e with priority p to the priority queue.
    void
    changePriority(E e, double p)
    Effect: Change the priority of element e to p.
    Effect: Remove (and return) the element of the priority queue with highest priority.
    boolean
    Returns: true iff the priority queue is empty.
    Returns: the element of the priority queue with highest priority, without changing the priority queue.
    int
    Returns: the number of elements in the priority queue.
    Returns a string that represents this priority queue: [item0:priority0, item1:priority1, ..., item(N-1):priority(N-1)] That is, the list is delimited by '[' and ']', and items are separated by ", " (a comma and a space).
  • Method Details

    • toString

      String toString()
      Returns a string that represents this priority queue: [item0:priority0, item1:priority1, ..., item(N-1):priority(N-1)] That is, the list is delimited by '[' and ']', and items are separated by ", " (a comma and a space).
      Overrides:
      toString in class Object
    • size

      int size()
      Returns: the number of elements in the priority queue.
    • isEmpty

      boolean isEmpty()
      Returns: true iff the priority queue is empty.
    • add

      void add(E e, double priority) throws IllegalArgumentException
      Effect: Add e with priority p to the priority queue. Throw an illegalArgumentException if e is already in the queue.
      Throws:
      IllegalArgumentException
    • peek

      E peek()
      Returns: the element of the priority queue with highest priority, without changing the priority queue. Requires: the priority queue is not empty.
    • extractMin

      E extractMin()
      Effect: Remove (and return) the element of the priority queue with highest priority. Requires: the priority queue is not empty.
    • changePriority

      void changePriority(E e, double p)
      Effect: Change the priority of element e to p. Requires: e is in the priority queue.