<aside> 💡 Compares all elements in a list and swaps their position each iteration

</aside>

Places the index of the first element


private int indexMin = 0;

Starts in the second element


You are checking if your element is lower than the other elements in the collection. But you don’t need to compare your element with itself, so just start in the second element.

Index update


Once you find an element lower than the current lowest you update the index variable.

indexMin = 4;

End of iteration


Change the position of the elements

swap(collectionName, indexToChange, indexMin)

Process


Just do this over all over again starting from the next element.