public class SelectionSort {
public static void main(String[] args) {
int[] array = {1,3,4,8,7,4,6,9,0};
for (int i : Selection(array)) {
System.out.println(i);
}
}
public static int[] Selection(int[] array){
for (int i = 0; i < array.length - 1; i++) {
int minIndex = i;
for (int j = i +1; j < array.length; j++) {
if (array[minIndex] > array[j]){
minIndex = j;
}
}
swap(array, i, minIndex);
}
return array;
}
public static void swap(int[] array, int i, int j){
if (i == j){
return;
}
array[i] = array[i] ^ array[j];
array[j] = array[i] ^ array[j];
array[i] = array[i] ^ array[j];
}
}