Iterates through the array and finds the new minimum element (in ascending order) from the unsorted subarray and moves it into the sorted subarray
public static int[] selectionSort(int[]arr){
int comparisons = 0;
for(int i = 0; i<arr.length-1; i++){
int min = i;
for(int j = i+1; j < arr.length; j++){
if(arr[j] < arr[min]){
min = j;
comparisons++;
}
if(min!=i){
int temp = arr[min];
arr[min] = arr[i];
arr[i] = temp;
System.out.print("\\n\\nNew array: " );
displayArr(arr);
System.out.println("\\nMinimum: " + min);
}
}
}
System.out.println("\\nSorted array number " + sortNum + ":");
displayArr(arr);
System.out.println("\\nNumber of comparisons done: " + comparisons);
sumComp+=comparisons;
sortNum++;
return arr;
}