home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PARADIS1 / COMBSORT.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-13  |  1KB  |  68 lines

  1. (5143)  Sun 9 Feb 92 15:56
  2. By: Jud Mccranie
  3. To: David G. Edwards
  4. Re: Insert Sort
  5. St:
  6. ---------------------------------------------------------------------------
  7.  DG> Would you mind posting an example of the Combination sort?
  8.  DG> Where'd you find it?
  9.  
  10.  
  11. const size = 500;
  12.  
  13. var list : array[ 1 .. size] of real;
  14.  
  15.  
  16. procedure CombSort( size : integer);
  17.  
  18. { comb (combination) sort, Stephen Lacy and Richard Box,
  19.   Byte, April 1991, 315-320. }
  20.  
  21. var i, j, gap  : integer;
  22.     NoSwitches : boolean;
  23.     temp       : real;
  24.  
  25.  
  26. begin
  27.  
  28. gap := size;
  29.  
  30. repeat
  31.   if gap < 3276
  32.     then gap := (10 * gap) div 13
  33.     else gap := trunc( 0.78923 * gap);
  34.  
  35.     if gap <= 0
  36.       then gap := 1
  37.       else if (gap = 9) or (gap = 10) then gap := 11;
  38.  
  39.   NoSwitches := true;
  40.  
  41.   for i := 1 to size - gap do
  42.   begin
  43.     j := i + gap;
  44.  
  45.     if list[ i] > list[ j] then
  46.     begin
  47.       temp       := list[ i];
  48.       list[ i]   := list[ j];
  49.       list[ j]   := temp;
  50.       NoSwitches := false
  51.     end
  52.  
  53.    end
  54.  
  55. until NoSwitches and (gap <= 1)
  56.  
  57. end; { --- comb sort --- }
  58.  
  59. I hope I'm not violating a copyright.  I cleaned up and optimized their
  60. code a little bit.  Pretty simple, like a cross between bubble and
  61. shell.  Runs about as fast as shell, which is generally fast enough.
  62.  
  63.  
  64. --- Via Silver Xpress V2.28
  65.  * Origin: The Bad Lands BBS 650+Megs (912)247-6977 (1:370/520)
  66.  
  67. @PATH: 370/520 510 20 151/1003 13/13 396/1 170/400 512/0 1007 
  68.