I've found the following algorithm for selection sort on the internet.
program SelectionSort(input,output); var A : Array[1..80] of Integer; n, i, j, k, m, loc, temp : Integer; begin writeln('size of the array?'); read(n); for i := 1 to n do read(A[i]); for k := 1 to n - 1 do begin m := A[k]; loc := k; for j := k + 1 to n do begin if m > A[j] then begin m := A[j]; loc := A[j]; loc := j; end; end; temp := A[k]; A[k] := A[loc]; A[loc] := temp; end; for i := 1 to n do begin writeln(A[i] : 3); end; readln(); readln(); end.
I'd like to gain a better understanding of how it actually does the sorting. Could someone please help me with this?