Program SelectionSort(output); const LO = 1; HI = 5; type IntArrayType = array [LO..HI] of integer; { Selection sort procedure; Sorts an array of ints in ascending order } procedure selection_sort(var intarray : IntArrayType; arrayLength : integer); var current, j : integer; temp, large : integer; begin for current := arrayLength downto 2 do begin large := 1; { Initialize large to index of first element. } { Find the largest element between the positions 1 and current. } for j := 2 to current do begin if (intarray[j] > intarray[large]) then large := j; end; { Swap the largest element found with element in position current. } temp := intarray[large]; intarray[large] := intarray[current]; intarray[current] := temp; end end; { Procedure that simply displays each element of intarray } procedure display_array(intarray : IntArrayType; arrayLength : integer); var i : integer; begin for i := 1 to arrayLength do write(intarray[i]: 3); writeln; end; var nums : IntArrayType; nums_length : integer; begin nums[1] := 20; nums[2] := 47; nums[3] := 17; nums[4] := 31; nums[5] := 34; nums_length := 5; writeln('Unsorted Array:'); display_array(nums, nums_length); selection_sort(nums, nums_length); writeln('Sorted Array:'); display_array(nums, nums_length) end.