我在我实现的方法上找不到符号错误,但拼写和参数正是它们应该是的。发生了什么事?
方法我正在尝试实施:
public static Comparable[] heapify(Comparable[] array){
int index = array.length - 1;
Comparable temp;
if (index == 1){
return array;
}
else{
for (int i = index; i >= 0; i++){
while(array[i/2] != null && array[i/2].compareTo(array[i]) > 0){
temp = array[i];
array[i] = array[i/2];
array[i/2] = temp;
index = index/2;
}
}
}
}
正在实施该方法的测试程序:
Comparable[] array = {2,5,8,12,10,6,4};
Heap heapified = heapify(array);
heapified.printHeap();
编辑:添加了编译器错误
G:\Labs\Lab_10>javac Test.java
Test.java:19: error: cannot find symbol
Heap heapified = heapify(array);
^
symbol: method heapify(Comparable[])
location: class Test
Note: .\Heap.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
答案 0 :(得分:1)
请提供更多信息。现在它帮助太小了。
但是,我的猜测是:
方法“heapify(Comparable [])”在不同的类中,所以你写的是:
堆heapified = CLASS_WITH_HEAPIFY.heapify(array);
检查主类中的导入。也许您没有使用包含'heapify'