-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelect.java
More file actions
34 lines (28 loc) Β· 841 Bytes
/
Select.java
File metadata and controls
34 lines (28 loc) Β· 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package basic.sort.impl;
import basic.sort.Sort;
/*
Select μ ν μ λ ¬
- μ λ ¬λμ§ μμ κ³³μμ κ°μ₯ μμ μλ₯Ό μ°Ύμ κ·Έκ²μ 맨 μμ λ°°μΉ
- O(N^2) μ μκ° λ³΅μ‘λλ₯Ό κ°μ§
- λ°μ΄ν° ν¬κΈ°κ° ν¬μ§ μμ κ²½μ° μλκ° λΉ λ¦.
- ν΅μ¬ κ°μ₯ μμ μκ° λ§¨ μμ λ°°μΉ
*/
public class Select implements Sort {
@Override
public void sort(int[] array) {
int minIndex;
int minValue;
for(int i=0;i<array.length-1;i++){
minIndex = i;
minValue= array[i];
for(int j=i+1;j<array.length;j++){
if(array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
swap(array, i, minIndex);
printAllArray(array,i);
}
}
}