home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / SHELL.PRO < prev    next >
Text File  |  1993-05-12  |  2KB  |  60 lines

  1.        |            --------------------------
  2.        |            -- Shell sort Benchmark --
  3.        |            --------------------------
  4.        |without type_check -- makes no difference
  5.        |
  6.        |constant ITERATIONS = 1 -- was 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.      1 |    last = length(x)
  20.      1 |    gap = floor(last / 4) + 1
  21.      1 |    while TRUE do
  22.      4 |     first = gap + 1
  23.      4 |    for i = first to last do
  24.    180 |        tempi = x[i]
  25.    180 |        j = i - gap 
  26.    180 |        while TRUE do
  27.    303 |        tempj = x[j]
  28.    303 |        if tempi >= tempj then
  29.    166 |            j = j + gap
  30.    166 |            exit
  31.        |        end if
  32.    137 |        x[j+gap] = tempj
  33.    137 |        if j <= gap then
  34.     14 |            exit
  35.        |        end if
  36.    123 |        j = j - gap
  37.        |        end while
  38.    180 |        x[j] = tempi
  39.        |    end for
  40.      4 |    if gap = 1 then
  41.      1 |        return x
  42.        |    else
  43.      3 |        gap = floor(gap / 4) + 1 
  44.        |    end if
  45.        |    end while
  46.        |end function
  47.        |
  48.      1 |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.      1 |t = time()
  53.        |
  54.      1 |for i = 1 to ITERATIONS do 
  55.      1 |    slist = shell_sort(list)
  56.        |end for
  57.      1 |printf(1, "%d iterations in %.2f seconds\n", {ITERATIONS, time() - t})
  58.      1 |? slist
  59.  
  60.