for i=1 to data 개수 do
for j = i to data 개수 do
if min > data[j] then
min -> data[j]
index = j
swap data[i], data[j]
3 5 7 2 4 1 9 8 6 10 정렬
public class SelectionSort {
public static void main(String []args) {
int i, j, min, temp, index=0;
int[] array = {3, 5, 7, 2, 4, 1, 9, 8, 6, 10};
for(i =0 ; i < array.length; i++) {
min = 9999;
for(j = i; j < array.length; j++) {
if(min > array[j]) {
min = array[j];
index = j;
}
}
temp = array[i];
array[i] = array[index];
array[index] = temp;
}
for(i=0;i<array.length;i++) {
System.out.print(array[i] + " ");
}
System.out.println();
}
}
이미지 출처 : https://github.com/GimunLee/tech-refrigerator/
선택 정렬 헷갈렸는데 잘 보고 갑니다 o( ̄▽ ̄)d !!