home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d07xx
/
d0713.lha
/
ICalc
/
Scripts
/
sort.ic
< prev
next >
Wrap
Text File
|
1992-08-19
|
410b
|
18 lines
# This is the Shell-sort, probably best for smallish arrays.
# Sorts by real part.
# nb: routines assume array base is 1
func swap(*a, *b) = { local t; t = a; a = b; b = t; }
func sort(@a) = {
local n, gap, k, j
n = sizeof(a)
for (gap = floor(n/2); gap > 0; gap = floor(gap*0.5))
for (k = gap; k < n; k += 1)
for (j = k-gap+1; j >= 1 && a[j] > a[j+gap]; j -= gap)
swap(a[j],a[j+gap])
return
}