import java.util.Arrays;
public class SelectionSort {
public static int[] arr = {3, 2, 4, 1, 6, 8, 0};
/*
* 0, 2, 4, 1, 6, 8, 3 N-1
* 0, 1, 4, 2, 6, 8, 3 N-2
* 0, 1, 2, 4, 6, 8, 3
* 0, 1, 2, 3, 6, 8, 4
* 0, 1, 2, 3, 4, 8, 6
* 0, 1, 2, 3, 4, 6, 8 1
* 0, 1, 2, 3, 4, 6, 8 0
*
* (N-1)(N-2)/2 ~ N-square/2 compares
* N-1 swap
*/
public static int[] sort(int[] a) {
for (int i = 0; i < a.length; i++) {
int min = i;
for(int j = i; j < a.length; j++) {
if(a[min] > a[j]) min = j;
}
int t = a[min];
a[min]= a[i];
a[i]=t;
}
return a;
}
public static void main(String[] args) {
Arrays.stream(sort(arr)).forEach(System.out::println);
}
}