Author: Misha Moellner
Selection sort algorithm
Answer:
Selection Sort
An elementary sorting algorithm that is designed to minimize the number of
exchanges that are performed. It works by making n-1 passes over the unsorted
portion of the array, each time selecting the largest value. This value is then
moved into its final sorted position with a single exchange.
1 procedure SelectionSort(Items: TStrings);
2 var3 i, n, maxIndex, topIndex: integer;
4 Dummy: string;
5 begin6 n := Items.Count;
7 8 for topIndex := n - 1 downto 1 do9 begin10 maxIndex := topIndex;
11 for i := 0 to topIndex - 1 do12 if Items[i] > Items[maxIndex] then13 maxIndex := i;
14 15 Dummy := Items[topIndex];
16 Items[topIndex] := Items[maxIndex];
17 Items[maxIndex] := Dummy;
18 end;
19 end;