public int[] selectionSort(int array[]) {
for(int i = array.length - 1; i >= 0; i--) {
int highestIndex = i;
for(int j = i; j >= 0; j--) {
if(array[j] > array[highestIndex])
highestIndex = j;
}
int temp = array[i];
array[i] = array[highestIndex];
array[highestIndex] = temp;
}
return array;
}
선택 분류의 개념을 이해하지만 코드가 혼란 스럽습니다. 특히 누군가가 "int temp = array [i];"로 시작하는 바깥 for 루프의 마지막 세 문장에서 무슨 일이 일어나는지 설명 할 수 있습니까?코드 세그먼트 이해에 도움이 필요합니다.
http://stackoverflow.com/questions/13766209/effective-swapping-of-elements-of-an-array-in-java –
당신은'array [i]'와'array [highestIndex] '. 이것을하기 위해서 당신은'array [i]'의 사본을 만들어서'array [i] = array [highestIndex]; '에 의해 덮어 쓰여진 값에 접근 할 수 있습니다. – Gendarme