问题是我正在尝试修复最大 heapify,但由于错误不断发生,它无法正常工作。我一直在关注几本书的伪代码,但仍然显示错误。我正在尝试通过使用to exchangeA[i]
来交换to 但它却给出了错误A[largest]
=
class Heap {
// public for JUnit testing purposes
public ArrayList<Integer> array;
public int heap_size;
public Heap(int size) {
}
public Heap(List<Integer> source) {
this(source, false);
}
public Heap(List<Integer> source, boolean incremental) {
}
public static int parent(int index) {
return index/2;
}
public static int left(int index) {
return 2 * index;
}
public static int right(int index) {
return (2 * index) + 1;
}
public void maxHeapify(int i, int A)
{
int l = left(i);
int r = right(i);
if(l <= A.heap_size && A[l] > A[i])
largest = l;
else
largest = i;
if(r <= A.heap_size && A[r] > A[largest])
largest = r;
if(largest != i)
{
A[i] = A[largest];
maxHeapify(A,largest);
}
}
public void buildMaxHeap() {
}
public void insert(Integer k) {
}
public Integer maximum() {
return 0;
}
public Integer extractMax() {
return 0;
}
}
我期待它运行,但我得到一个错误
Heap.java:31: error: int cannot be dereferenced
if(l <= A.heap_size && A[l] > A[i])
^
Heap.java:31: error: array required, but int found
if(l <= A.heap_size && A[l] > A[i])
^
Heap.java:31: error: array required, but int found
if(l <= A.heap_size && A[l] > A[i])
^
Heap.java:32: error: cannot find symbol
largest = l;
^
symbol: variable largest
location: class Heap
如果可以,请帮忙。