Class SlowPQueue<E>

java.lang.Object
datastructures.SlowPQueue<E>
All Implemented Interfaces:
PQueue<E>

public class SlowPQueue<E> extends Object implements PQueue<E>
A slow implementation of a priority queue where the priorities are doubles. An asymptotically more efficient implementation is possible!
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates: an empty 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 priority)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface datastructures.PQueue

    toString
  • Constructor Details

    • SlowPQueue

      public SlowPQueue()
      Creates: an empty queue
  • Method Details

    • size

      public int size()
      Description copied from interface: PQueue
      Returns: the number of elements in the priority queue.
      Specified by:
      size in interface PQueue<E>
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: PQueue
      Returns: true iff the priority queue is empty.
      Specified by:
      isEmpty in interface PQueue<E>
    • peek

      public E peek()
      Description copied from interface: PQueue
      Returns: the element of the priority queue with highest priority, without changing the priority queue. Requires: the priority queue is not empty.
      Specified by:
      peek in interface PQueue<E>
    • add

      public void add(E e, double priority) throws IllegalArgumentException
      Description copied from interface: PQueue
      Effect: Add e with priority p to the priority queue. Throw an illegalArgumentException if e is already in the queue.
      Specified by:
      add in interface PQueue<E>
      Throws:
      IllegalArgumentException
    • extractMin

      public E extractMin()
      Description copied from interface: PQueue
      Effect: Remove (and return) the element of the priority queue with highest priority. Requires: the priority queue is not empty.
      Specified by:
      extractMin in interface PQueue<E>
    • changePriority

      public void changePriority(E e, double priority)
      Description copied from interface: PQueue
      Effect: Change the priority of element e to p. Requires: e is in the priority queue.
      Specified by:
      changePriority in interface PQueue<E>