我有这个堆排序代码,它最初是为了对整数数组进行排序而编写的,但我需要对类中的 Object[] 进行排序。对于这些行,我不断收到此错误:
public static void heapSort(Object[] myArray, int length) {
Object temp;
int size = length-1;
for (int i = (length / 2); i >= 0; i--) {
heapify(myArray, i, size);
};
for(int i= size; i>=0; i--) {
temp = myArray[0];
myArray[0] = myArray[size];
myArray[size] = temp;
size--;
heapify(myArray, 0, size);
}
}
public static void heapify (Object [] myArray, int i, int heapSize) {
int a = 2*i;
int b = 2*i+1;
int largestElement;
if (a<= heapSize && …Run Code Online (Sandbox Code Playgroud)