// selection sort
a1 = arr[1, 10, 5, 6, 4, 7, 19]
fun Selection_Sort(@init
array):
n = length(array)
// Outer loop: iterate thru all index positions except the last
for (i = 0, i < n - 1, i += 1):
// assume the current index position holds min element
@mark minIdx = i
// Inner loop: find actual minimum element in remaining
// unsorted portion of array
for (j = i + 1, j < n, j += 1):
@mark if (array[j] < array[minIdx]):
@mark minIdx = j; // new minimum value index found
end if
end for
// Swap Values when a smaller value is encountered
@mark swap(array[i], array[minIdx])
end for
return array
end fun
result = Selection_Sort(a1)