procedure selectionSort( A : list of sortable items ) n = length(A) for i = n-1 to 1 inclusive do (note the reverse order) maxPosition = 0 for j = 1 to i inclusive do if A[j] > A[maxPosition] maxPosition = j end if end for swap A[maxPosition] with A[i] end for end procedure