Selection sort is a straightforward, comparison-based sorting algorithm. It partitions the array into a sorted prefix and an unsorted suffix. On each pass, it finds the smallest (or largest) element in the unsorted portion and swaps it into the next position of the sorted prefix.
procedure selection_sort(A):
n = length(A)
for i from 0 to n - 2:
min_index = i
for j from i + 1 to n - 1:
if A[j] < A[min_index]:
min_index = j
if min_index != i:
swap A[i], A[min_index]
return A
Array: [64, 25, 12, 22, 11]
Now sorted.