home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / SHELL.EX < prev    next >
Text File  |  1993-05-31  |  1KB  |  59 lines

  1.             --------------------------
  2.             -- Shell sort Benchmark --
  3.             --------------------------
  4. without type_check -- makes no difference
  5.  
  6. constant ITERATIONS = 20000
  7.  
  8. constant TRUE = 1
  9.  
  10. sequence list, slist
  11.  
  12. function shell_sort(sequence x)
  13. -- Shell sort 
  14. -- will sort any sequence of integers
  15.     integer gap, j
  16.     integer first, last 
  17.     integer tempi, tempj
  18.  
  19.     last = length(x)
  20.     gap = floor(last / 4) + 1
  21.     while TRUE do
  22.      first = gap + 1
  23.     for i = first to last do
  24.         tempi = x[i]
  25.         j = i - gap 
  26.         while TRUE do
  27.         tempj = x[j]
  28.         if tempi >= tempj then
  29.             j = j + gap
  30.             exit
  31.         end if
  32.         x[j+gap] = tempj
  33.         if j <= gap then
  34.             exit
  35.         end if
  36.         j = j - gap
  37.         end while
  38.         x[j] = tempi
  39.     end for
  40.     if gap = 1 then
  41.         return x
  42.     else
  43.         gap = floor(gap / 4) + 1 
  44.     end if
  45.     end while
  46. end function
  47.  
  48. list = {9, 34, 14, 18, 33, 46, 11, 13, 7, 26, 22, 10, 36, 40, 2, 28, 32, 1,
  49.     23, 31, 43, 5, 24, 42, 45, 50, 16, 3, 47, 39, 21, 49, 41, 6, 19, 30,
  50.     20, 35, 44, 38, 25, 15, 27, 17, 8, 4, 29, 37, 48, 12}
  51. atom t
  52. t = time()
  53.  
  54. for i = 1 to ITERATIONS do 
  55.     slist = shell_sort(list)
  56. end for
  57. printf(1, "%d iterations in %.2f seconds\n", {ITERATIONS, time() - t})
  58. ? slist
  59.