Skip to content

Commit 0627441

Browse files
committed
feat: 선택 정렬 구현
1 parent fa93c62 commit 0627441

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package sort;
2+
3+
public class SelectionSort implements Sort {
4+
5+
@Override
6+
public void sort(int[] array) {
7+
int length = array.length;
8+
int maxIndex;
9+
int temp;
10+
for (int i = 0; i < length - 1; i++) {
11+
maxIndex = i;
12+
for (int j = i + 1; j < length; j++) { // 최솟값 탐색
13+
if (array[j] < array[maxIndex]) {
14+
maxIndex = j;
15+
}
16+
}
17+
18+
// swap
19+
temp = array[i];
20+
array[i] = array[maxIndex];
21+
array[maxIndex] = temp;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)