Sifting I。 walk up the list I 。where you are at in the list is current position I 。everything before current position must be in order I 。put current position in order I。 advance current position I 。things put in order by swapping
public class SelectionSortExample { public static void selectionSort(int[] arr){ for (int i = 0; i < arr.length - 1; i++) { int index = i; for (int j = i + 1; j < arr.length; j++){ if (arr[j] < arr[index]){ index = j;//searching for lowest index } } int smallerNumber = arr[index]; arr[index] = arr[i]; arr[i] = smallerNumber; } }