什么是我实现此队列的最简单方法,以便我可以在每个相应的 MyEntry 对象中保存每个索引(条目在 ArrayList 堆中的位置),而不使用键或值来执行此操作?
public class HeapPriorityQueue<K,V> {
protected ArrayList<Entry<K,V>> heap;
protected Comparator<K> comp;
protected static class MyEntry<K,V> implements Entry<K,V> {
protected K key;
protected V value;
public MyEntry(K k, V v) {key = k; value = v;}
public K getKey() {return key;}
public V getValue() {return value;}
public String toString() {return "(" + key + "," + value + ")";}
}