program SelectSort; const MaxArray = 100; type DayType = (Su, Mo, Tu, We, Th, Fr, Sa); SortRange = DayType; TestRange = SortRange; SortElt = Char; SortArrayType = array[SortRange] of SortElt; TestArrayType = SortArrayType; var Sort : SortArrayType; Today : SortRange; {counter, and the array size} 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 Character to grade each day of the week'); WriteLn; for Today := Su to Sa do Read(Sort[Today]); SelSort(Sort,Mo,Fr); WriteLn; WriteLn('The grades in sorted order are:'); for Today := Mo to Fr do Write(Sort[Today]:2); WriteLn; end.{main}