import java.util.Comparator; /** * Abstract base class for priority queue implementations. This * gives the basic functions and interface required for a priority queue. * It might have been better done with an interface that had the methods * and have this class implement the interface (like the Java API does * with lists, maps, etc.) but that would have been overkill for the * probably scope of usage this class will receive. */ public abstract class PriorityQueue { /** * Constructs a new, empty priority queue according to the given * comparator. All objects inserted into the priority queue must * be mutually comparable using the comparator c. * * @param c the comparator that will be used to order this queue. */ public PriorityQueue(Comparator c) { comparator = c; } /** * Returns true if priority queue has no elements * * @return true if the priority queue has no elements */ public abstract boolean isEmpty(); /** * Returns a reference to the minimum element in the priority queue * * @return reference to the minimum element in the priority queue. */ public abstract Object findMin(); /** * Inserts a new object to the priority queue * * @param x Object to be inserted into the priority queue. */ public abstract void insert(Object x); /** * Removes the minimum element from the priority queue. * * @return reference to the minimum element. */ public abstract Object deleteMin(); /** * Erases all elements from the priority queue. */ public abstract void clear(); /** * Comparator used for ordering the elements in the priority queue. */ protected Comparator comparator; }