home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / pascal / swag / sorting.swg / 0005_BUBBLE2.PAS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-05-28  |  857 b   |  41 lines

  1. {
  2. > Does anyone know of a routine or code that would allow for
  3. > a alphbetical sort in pascal?  If so could you mail or
  4. > Write it in this base?  Thanks!
  5.  
  6. I know of a couple but this is the best and fastest one that I know of
  7.  
  8. Bubble Sort
  9. }
  10.  
  11. Type
  12.   StArray = Array [1..10] of String;
  13.  
  14. Procedure bubble_sort(Var names : StArray);
  15. Var
  16.   i,
  17.   last,
  18.   latest : Integer;
  19.   temp : String;
  20.   exchanged : Boolean;
  21. begin
  22.   last := max_names - 1;
  23.   Repeat
  24.     i := 1;
  25.     exchanged := False;
  26.     latest    := last;
  27.     Repeat
  28.       if names[i] > names[i+1] then
  29.       begin
  30.         temp := names[i];
  31.         names[i] := names[i+1];
  32.         names[i+1] := temp;
  33.         exchanged := True;
  34.         latest := i;
  35.       end;
  36.       inc(i);
  37.     Until not (i <= last);
  38.     last := latest;
  39.   Until not ((last >= 2) and exchanged);
  40. end;
  41.