2 Selection Sort is an elementary sorting algorithm that is designed to minimize
\r
3 the number of exchanges that are performed.
\r
4 It works by making N-1 passes over the unsorted portion of the array, each time
\r
5 selecting the largest value. This value is then moved into its final sorted
\r
6 position with a single exchange.
\r
7 Here is a procedure that implements Selection Sort, assuming a global array a[ ]
\r
8 with n elements, and a procedure called swap( ).
\r
12 procedure selection_sort;
\r
18 for top := n downto 2 do
\r
21 for i := 1 to top-1 do
\r
22 if a[i] > a[max] then
\r
29 DOWNLOAD selection.pas (complete program)
\r
30 Selection Sort requires about N2/2 comparisons and about N exchanges, and is
\r
31 quite insensitive to the original ordering of the input data.
\r