home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / sampler / 02 / sort / sort2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-02-29  |  737 b   |  26 lines

  1. procedure Sort(var List : ListType; Count : Word);
  2. {
  3.    preconditions:  BaseType is a type for which the operators
  4.                      :=, <>, and < all are defined
  5.                    ListType = array[1..Limit] of BaseType
  6.                    Count is in the range 0..Limit
  7.    postconditions: The elements 1..Count of List are sorted
  8.                      in ascending order
  9. }
  10. var
  11.   Top,Min,K : Integer;
  12.   Temp      : BaseType;
  13. begin
  14.   for Top := 1 to Count-1 do begin
  15.     Min := Top;
  16.     for K := Top+1 to Count do
  17.       if List[K] < List[Min]
  18.         then Min := K;
  19.     if Top <> Min then begin
  20.       Temp := List[Top];
  21.       List[Top] := List[Min];
  22.       List[Min] := Temp
  23.     end
  24.   end
  25. end; { of proc Sort }
  26.