Janilabo

Janilabo | TSASelectionSort() [Simba]

May 21st, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.91 KB | None | 0 0
  1. procedure TSASelectionSort(var TSA: TStringArray; order: (so_LowToHigh, so_HighToLow));
  2. var
  3.   c, t, h, m: Integer;
  4.   tmp: string;
  5. begin
  6.   h := High(TSA);
  7.   if (h > 0) then
  8.   case order of
  9.     so_LowToHigh:
  10.     for c := 0 to h do
  11.     begin
  12.       m := c;
  13.       for t := (c + 1) to h do
  14.         if (TSA[m] > TSA[t]) then
  15.           m := t;
  16.       tmp := TSA[m];
  17.       TSA[m] := TSA[c];
  18.       TSA[c] := tmp;
  19.     end;
  20.     so_HighToLow:
  21.     for c := 0 to h do
  22.     begin
  23.       m := c;
  24.       for t := (c + 1) to h do
  25.         if (TSA[m] < TSA[t]) then
  26.           m := t;
  27.       tmp := TSA[m];
  28.       TSA[m] := TSA[c];
  29.       TSA[c] := tmp;
  30.     end;
  31.   end;
  32. end;
  33.  
  34. var
  35.   TSA: TStringArray;
  36.  
  37. begin
  38.   TSA := ['Apple', 'Orange', 'Lemon', 'Banana', 'Pear'];
  39.   TSASelectionSort(TSA, so_HighToLow); // Reversed.
  40.   WriteLn(ToStr(TSA));
  41.   TSASelectionSort(TSA, so_LowToHigh); // Default.
  42.   WriteLn(ToStr(TSA));
  43. end.
Advertisement
Add Comment
Please, Sign In to add comment