Example Code:
procedure selection( var a : anarray; N : integer);

 var i, j, min : integer;

begin
 
 for i := 1 to N-1 do
  begin

   {Elements from 1 to i-1 are in the correct place}

   min := i;
   for j := i+1 to N do
    if a[j] < a[min] then min := j;

   swap(a[i], a[min]);

   {Elements from 1 to i are in the correct place}

  end;

end;

Back to Sorting Algorithms