home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
progmisc
/
euphor10.zip
/
SHELL.PRO
< prev
next >
Wrap
Text File
|
1993-05-12
|
2KB
|
60 lines
| --------------------------
| -- Shell sort Benchmark --
| --------------------------
|without type_check -- makes no difference
|
|constant ITERATIONS = 1 -- was 20000
|
|constant TRUE = 1
|
|sequence list, slist
|
|function shell_sort(sequence x)
|-- Shell sort
|-- will sort any sequence of integers
| integer gap, j
| integer first, last
| integer tempi, tempj
|
1 | last = length(x)
1 | gap = floor(last / 4) + 1
1 | while TRUE do
4 | first = gap + 1
4 | for i = first to last do
180 | tempi = x[i]
180 | j = i - gap
180 | while TRUE do
303 | tempj = x[j]
303 | if tempi >= tempj then
166 | j = j + gap
166 | exit
| end if
137 | x[j+gap] = tempj
137 | if j <= gap then
14 | exit
| end if
123 | j = j - gap
| end while
180 | x[j] = tempi
| end for
4 | if gap = 1 then
1 | return x
| else
3 | gap = floor(gap / 4) + 1
| end if
| end while
|end function
|
1 |list = {9, 34, 14, 18, 33, 46, 11, 13, 7, 26, 22, 10, 36, 40, 2, 28, 32, 1,
| 23, 31, 43, 5, 24, 42, 45, 50, 16, 3, 47, 39, 21, 49, 41, 6, 19, 30,
| 20, 35, 44, 38, 25, 15, 27, 17, 8, 4, 29, 37, 48, 12}
|atom t
1 |t = time()
|
1 |for i = 1 to ITERATIONS do
1 | slist = shell_sort(list)
|end for
1 |printf(1, "%d iterations in %.2f seconds\n", {ITERATIONS, time() - t})
1 |? slist