-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathTask12Main.java
More file actions
32 lines (27 loc) · 962 Bytes
/
Task12Main.java
File metadata and controls
32 lines (27 loc) · 962 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
package com.example.task12;
public class Task12Main {
public static void main(String[] args) {
//здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
// например вот так:
/*
int[] arr = {9, 11, 7, 8};
selectionSort(arr);
System.out.println(java.util.Arrays.toString(arr));
*/
}
static void selectionSort(int[] arr) {
if (arr == null || arr.length == 0) return;
for (int i = 0; i < arr.length; i++){
int min = Integer.MAX_VALUE;
int numMin = 0;
for (int j = i; j < arr.length; j++){
if (arr[j] <= min){
min = arr[j];
numMin = j;
}
}
arr[numMin] = arr[i];
arr[i] = min;
}
}
}