Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
procedure main() #: demonstrate various ways to sort a list and string
|
||||
demosort(combsort,[3, 14, 1, 5, 9, 2, 6, 3],"qwerty")
|
||||
end
|
||||
|
||||
procedure combsort(X,op) #: return sorted X
|
||||
local gap,swapped,i
|
||||
|
||||
op := sortop(op,X) # select how and what we sort
|
||||
|
||||
swappped := gap := *X # initialize gap size and say swapped
|
||||
until /swapped & gap = 1 do {
|
||||
gap := integer(gap / 1.25) # update the gap value for a next comb
|
||||
gap <:= 1 # minimum gap of 1
|
||||
swapped := &null
|
||||
|
||||
i := 0
|
||||
until (i +:= 1) + gap > *X do # a single "comb" over the input list
|
||||
if op(X[i+gap],X[i]) then
|
||||
X[i+1] :=: X[swapped := i] # swap and flag as unsorted
|
||||
}
|
||||
return X
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue