for (int j = 0; j < n - 1; j++) { int minIndex = j; int k = j + 1; // scan the rest of the array if (elements[k] < elements[minIndex]) { minIndex = k; } // repeat compare/update until k reaches end int temp = elements[j]; elements[j] = elements[minIndex]; elements[minIndex] = temp;}// done ✅
j (Current target)
k (Scanning)
minIndex (Smallest found)
Sorted portion
Welcome! Press Step or Play to begin the sorting process.