/** Implementation of a priority queue by means of a sorted list */ public class SortedListPriorityQueue implements PriorityQueue { protected List L; protected Comparator c; protected Position actionPos; // variable used by subclasses /** Inner class for entries */ protected static class MyEntry implements Entry { protected Object k; // key protected Object v; // value public MyEntry(Object key, Object value) { k = key; v = value; } // methods of the Entry interface public Object key() { return k; } public Object value() { return v; } } /** Inner class for a default comparator using the natural ordering */ protected static class DefaultComparator implements Comparator { public DefaultComparator() { /* default constructor */ } public int compare(Object a, Object b) throws ClassCastException { return ((Comparable) a).compareTo(b); } } /** Creates the priority queue with the default comparator. */ public SortedListPriorityQueue () { L = new NodeList(); c = new DefaultComparator(); } /** Creates the priority queue with the given comparator. */ public SortedListPriorityQueue (Comparator comp) { L = new NodeList(); c = comp; }