전 교수진이 있으며, 삽입 분류를 사용하고 싶습니다. 난에서 오류가 발생합니다 :오브젝트 배열을 사용한 삽입 정렬?
InsertionSort.insertionSortA(faculty, faculty.length);
오류은 말한다 : "방법 insertionSortA 클래스 삽입 정렬에 주어진 타입에 적용 할 수 없습니다
필요 : 대등 [], int로
발견 학부 [], INT
InsertionSort.insertionSortA((Comparable[]) faculty, faculty.length);
나는 내가 가진 경우 정수 [] 배열이 작동 것이라고 알고 있지만, 나는 왜 내 학부 [] 료를 혼란 스러워요 :
나는이 일을하는 것은 작동하지 않을 것이라는 점을 알고있다 일하지 않아?
public class Tester {
public static void main(String[] args) {
InsertionSort insertionSort = new InsertionSort();
Education edu = new Education ("BA", "Business", 1);
Education edu2 = new Education ("BA", "Health Science", 1);
Education edu3 = new Education ("BA", "Computer Science", 1);
Faculty[] faculty = new Faculty[] {
new Faculty ("538", "Doe", "Jane", 'M', 1994,1,10,
"Assistant", edu),
new Faculty ("238", "Do", "John", 'F', 1994,6,1,
"Assistant", edu2),
new Faculty ("080", "White", "Snow", 'F', 1994,4,22,
"Full", edu3)
};
InsertionSort.insertionSortA(faculty, faculty.length);
}
} 요소 수, 비교 논리는 2 교수진을 비교하는 방법의 기초이다 (비교해야 배열/컬렉션 삽입 정렬을 적용하기 위해
public class InsertionSort {
public static void insertionSortA(Comparable[] theArray, int n) {
for (int unsorted = 1; unsorted < n; ++unsorted) {
Comparable nextItem = theArray[unsorted];
int loc = unsorted;
while ((loc > 0) &&(theArray[loc-1].compareTo(nextItem) > 0)) {
theArray[loc] = theArray[loc-1];
loc--;
} // end while
theArray[loc] = nextItem;
} // end for
} // end insertionSort
public static void insertionSortB(Comparable[] theArray, int n) {
for (int unsorted = 1; unsorted < n; ++unsorted) {
Comparable nextItem = theArray[unsorted];
int loc = unsorted;
while ((loc > 0) &&(theArray[loc-1].compareTo(nextItem) < 0)) {
theArray[loc] = theArray[loc-1];
loc--;
} // end while
theArray[loc] = nextItem;
} // end for
}
}