public class QuickSort {
private static <T extends Comparable<T>> int partition(T[] table, int first, int last) {
T pivot = table[first];
int up = first;
int down = last;
do {
while ((up < last) && (pivot.compareTo(table[up]) >= 0)) {
up++;
}
while (pivot.compareTo(table[down]) < 0) {
down--;
}
if (up < down) {
swap(table, up, down);
}
}while (up < down);
swap(table, first, down);
return down;
}
public static void swap(int A[], int x, int y){
int temp = A[x];
A[x] = A[y];
A[y] = temp;
}
}
我认为它与int A[]
有关,但我不确定如何修复它
答案 0 :(得分:2)
table
的类型为T[]
(隐式对象数组),您的交换方法需要int[]
。
将交换更改为:
public static void swap(Object A[], int x, int y){
Object temp = A[x];
A[x] = A[y];
A[y] = temp;
}