바이너리 파일에서 작동하는 정렬 방법을 쓰고 있습니다. (전체 작업을 메모리에 읽지 않고 파일 내에서 수행 된 모든 작업).자바 : qsort 구현에 비교기 전달
다음과 같이 표시됩니다.qsort 메서드에서 "Comparator 형식의 메서드 비교 (E, E)가 인수 (so)에 적용되지 않음" " 이 표시됩니다.
왜 볼 수 있습니까?
감사합니다.
코드 :
class so {
// Some object
}
class compareByIntValue implements Comparator<so> {
public int compare(so o1, so o2) {
// Comparing
}
}
class StructureOnFile {
public static void main(String[] args) throws IOException {
RandomAccessFile objectsOnFile = new RandomAccessFile(FILENAME, "rw");
fillWithObjects(objectsOnFile);
quickSort(objectsOnFile, RecordSize, new compareByIntValue());
.
.
.
}
static <E> void quickSort(RandomAccessFile raf,
int RecordSize, Comparator<E> c) throws IOException {
quickSort(raf, RecordSize, c, 0, (int) (raf.length() - RecordSize));
}
static <E> void quickSort(RandomAccessFile raf,
int RecordSize, Comparator<E> c, int first, int last) {
if (last > first) {
int pivotIndex = partition(raf, RecordSize, first, last, c);
quickSort(raf, RecordSize, c, first, pivotIndex - RecordSize);
quickSort(raf, RecordSize, c, pivotIndex + RecordSize, last);
}
}
static <E> int partition(RandomAccessFile list,
int RecordSize, int first, int last, Comparator<E> c) {
so pivot = new so();
so tmp = new so();
list.seek(first);
pivot.readFromFile(list); // Reads first element into pivot
int low = first + RecordSize; // Index for forward search
int high = last; // Index for backward search
while (high > low) {
// Search forward from left
list.seek(low);
tmp.readFromFile(list);
HERE =================> while (low <= high && c.compare(tmp, pivot) <= 0)
low+=RecordSize;**