(* Author: Kingston *) (* Pre: a LTE b + 1 *) (* SelectionSort(A, a, b) *) (* Post: A[a] LTE A[a+1] LTE A[a+2] LTE ... A[b] *) (* and A is a permutation of the input array *) procedure SelectionSort (var A: AType; a,b: integer); var i: integer; begin if a = b + 1 then (* do nothing *) else i := MinIndex(A, a, b); if (i <> a) then Swap(A[i],A[a]); end; SelectionSort(A, a + 1, b); end; end SelectionSort; (* MinIndex returns the index of a minimum element of the non-empty array A[i..j], and Swap(A[i],A[j] swaps A[i] and A[j] *)