Class MinPriorityQueue<T>

java.lang.Object
edu.uky.ai.util.MinPriorityQueue<T>
Type Parameters:
T - the type of object this queue will hold

public class MinPriorityQueue<T> extends Object
A min priority queue which, instead of using a Comparator, allows the user to specify a numeric key that should be associated with the item being added to the queue. When an item is popped off this queue, it will always be the item with the lowest key. This queue may hold multiple copies of the same object with different keys. This class relies on PriorityQueue.
Author:
Stephen G. Ware
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, empty min priority queue.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Tests whether this queue is empty.
    Returns, but does not remove, the object with the lowest key value (i.e.
    pop()
    Removes and returns to the object with the lowest key.
    void
    push(T element, double priority)
    Associates an object with a given key and adds it to the queue.
    int
    Returns the number of objects currently stored in this queue.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MinPriorityQueue

      public MinPriorityQueue()
      Constructs a new, empty min priority queue.
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Tests whether this queue is empty.
      Returns:
      true if it is empty, false otherwise
    • size

      public int size()
      Returns the number of objects currently stored in this queue.
      Returns:
      the size
    • peek

      public T peek()
      Returns, but does not remove, the object with the lowest key value (i.e. the next object to be removed).
      Returns:
      the object
    • push

      public void push(T element, double priority)
      Associates an object with a given key and adds it to the queue.
      Parameters:
      element - the object to add
      priority - the key to associate with the object
    • pop

      public T pop()
      Removes and returns to the object with the lowest key.
      Returns:
      the object