-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectsort.java
32 lines (28 loc) · 938 Bytes
/
selectsort.java
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class selectsort {
public static void main(String[] args) throws Exception{
BufferedReader bfReader = new BufferedReader(new InputStreamReader(System.in));
String[] str =bfReader.readLine().split(",") ;
int[] arr = Arrays.stream(str).mapToInt(Integer::parseInt).toArray();
int min;
int index = 0;
for(int i = 0; i < arr.length - 1; i++) {
min = arr[i];
for(int j = i+1; j <= arr.length - 1; j++) {
if(arr[j] < min) {
min = arr[j];
index = j;
}
}
if(index != i) {
arr[index] = arr[i];
arr[i] = min;
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}