public class SelectSortVersion3 {
public static void selectSort(int[] arr){
boolean sort = false;
int lastIndex = arr.length-1;
while (!sort) {
sort = true;
int m = 0;
for (int i = 0; i < lastIndex; i++) {
if (arr[m] < arr[i + 1]) {
m = i+1;
sort = false;
}
}
swap(arr,m,lastIndex);
lastIndex--;
}
}
public static void swap(int[] arr,int x,int y){
int current = arr[y];
arr[y] = arr[x];
arr[x] = current;
}
public static void main(String[] args) {
int[] arr = {3,1,44,233,52,521,423,45};
SelectSortVersion3.selectSort(arr);
System.out.println(Arrays.toString(arr));
}
}