Selection Sort
The second sorting method we used is called Selection Sort.
Completed Code
Explanation
selectionSort()
searches for the element with the lowest value.The lowest value is -25 with an index of 3.
-25 swaps places with the first element in the array 207. This way we now have the lowest value starting off our array.
Repeat the process, finding the next smallest value and putting it to the right of -25.
Repeat the process until the array is properly sorted.
Variables Explanation
minIdx
- the index of our smallest value. It is initially set to the first element in our array.temp
- a temporary variable to easily allow the value ofarr[minIdx]
to change.i
andj
- the indexes of the elements that are being compared.
Last updated