program SelectSort; const MaxArray = 100; type SortRange = 1..Maxarray; TestRange = SortRange; SortElt = Integer; SortArrayType = array[SortRange] of SortElt; TestArrayType = SortArrayType; var Sort : SortArrayType; I, Size : SortRange; {counter, and the array size} Sentinel : SortElt; function SmallPos(Lo,Hi : TestRange; FArray : TestArrayType) : TestRange; {returns position of smallest element between positions lo and hi} var TestPos, Small : TestRange; begin Small := Lo; for TestPos := Lo to Hi do if FArray[TestPos] < FArray[Small] then Small := TestPos; SmallPos := Small end;{SmallPos} procedure SelSort(var FSort : SortArrayType; LoPos, HiPos : SortRange); {ascending order selection sort of array FSort from LoPos to HiPos} var Pos, SP : SortRange; Temp : SortElt; begin for Pos := LoPos to Pred(HiPos) do begin Temp := FSort[Pos]; SP := SmallPos(Pos,HiPos,FSort); FSort[Pos] := FSort[SP]; FSort[SP] := Temp; end;{for J} end;{SelSort} begin{main} WriteLn('Input a sentinel value (Integer) to terminate input'); ReadLn(Sentinel); WriteLn('Input Integers, ending with ',Sentinel :2,' - at most ',Maxarray); WriteLn; WriteLn; I := 1; repeat read(Sort[I]); I := I + 1; until Sort[I-1] = Sentinel; Size := I - 2; SelSort(Sort,1,Size); for I := 1 to Size do Write(Sort[I]:2); WriteLn; end.{main}