-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
41 lines (28 loc) · 1 KB
/
SelectionSort.java
File metadata and controls
41 lines (28 loc) · 1 KB
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
35
36
37
38
39
package SaxaThinkData;
public class SelectionSort {
// i 와 j의 위치에 있는 값을 바꿥니다
public static void swapElements(int [] array, int i, int j){
int temp =array[i];
array[i] = array [j];
array[j] =temp;
// 상수 사간 연산 , 요소르 잀고 쓰는 것
}
public static int indexLowest(int[] array, int start) {
int lowIndex = start;
for (int i = start; i < array.length; i++) {
if (array[i] < array[lowIndex]) {
lowIndex = i;
}
}
return lowIndex;
}
// 선형 linearly: start boshlangan kichkina narxdan boshlab joylashuvni ushlab (start ni ham uz ichiga oladi)
// 배열ni ohirigacha boradi
// 선택 정렬을 사용하여 요소를 정렬합니다.
public static void selectionSort(int[] array){
for (int i=0; i<array.length; i++){
int j =indexLowest(array , i);
swapElements(array ,i,j);
}
}
}