Campbell Ritchie wrote:Welcome to the Ranch
I think you are confusing yourself with the names of the parameters for that method. You called them minIndex and maxIndex, but they aren't the indices of the minimum or maximum. If you called them startIndex and endIndex, maybe you would find the method easier to understand.
Do you want the two indices to work on the start‑inclusive end‑exclusive convention? If you were at a more advanced stage, you would probably verify that the two indices are within the bounds of the array before starting the method.
Yes, it would be a good idea to call the method findMinIndex() or similar.
With this code I received 5, we now have the index for arr[4].
Do you by any chance know how to write the code for the selection sort algorithm?
This is how it was explained to me:
If we look at the selection sort algorithm, we start with a full array, search the minimum, swap it to the front, then reduce the view on the array by one. There are two variables needed—one for the start index and the other for the end index—and a loop that iterates over the array's elements repeatedly until the view is empty (start == end index). During the loop, we find the minimum, swap it to the front, and then decrease the view by one (startIndex++).