我迷失在代码中。我正在尝试将返回值添加到 ArrayList 中。返回的值被打印出来,我尝试将其转换为可以将其添加到 ArrayList。但似乎没有任何效果。
我public void getHeap()
喜欢从中检索return
值public double remove()
以添加到 ArrayList 中。它一直在告诉我source not found
。有什么帮助吗?
谢谢!
public class MinHeap<E extends Comparable<E>> {
List<E> h = new ArrayList<E>();
ArrayList<Double> arrayPostingsList = new ArrayList<Double>();
public void getHeap() {
MinHeap<Double> heap = new MinHeap<Double>(new Double[]{0.5015530788463572, 0.5962770626486013, 0.4182157748994399});
ArrayList<Double> newArray = new ArrayList<Double>();
System.out.println();
while (!heap.isEmpty()) {
System.out.println(heap.remove());
newArray.add(heap.remove());
}
}
public double remove() {
E removedNode = h.get(0);
E lastNode = h.remove(h.size() - 1);
percolateDown(0, lastNode);
return (Double) removedNode;
}
public MinHeap() {
}
public MinHeap(E[] keys) {
for (E key : keys) {
h.add(key);
}
for (int k = h.size() / 2 - 1; k >= 0; k--) {
percolateDown(k, h.get(k));
}
}
public void add(E node) {
h.add(null);
int k = h.size() - 1;
while (k > 0) {
int parent = (k - 1) / 2;
E p = h.get(parent);
if (node.compareTo(p) >= 0) {
break;
}
h.set(k, p);
k = parent;
}
h.set(k, node);
}
public E min() {
return h.get(0);
}
public boolean isEmpty() {
return h.isEmpty();
}
void percolateDown(int k, E node) {
//....
}
}