Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,25 @@
|
|||
procedure main() #: demonstrate various ways to sort a list and string
|
||||
write("Sorting Demo using ",image(beadsort))
|
||||
writes(" on list : ")
|
||||
writex(UL := [3, 14, 1, 5, 9, 2, 6, 3])
|
||||
displaysort(beadsort,copy(UL))
|
||||
end
|
||||
|
||||
procedure beadsort(X) #: return sorted list ascending(or descending)
|
||||
local base,i,j,x # handles negatives and zeros, may also reduce storage
|
||||
|
||||
poles := list(max!X-(base := min!X -1),0) # set up poles, we will track sums not individual beads
|
||||
every x := !X do { # each item in the list
|
||||
if integer(x) ~= x then runerr(101,x) # ... must be an integer
|
||||
every poles[1 to x - base] +:= 1 # ... beads "fall" into the sum for that pole
|
||||
}
|
||||
|
||||
|
||||
every (X[j := *X to 1 by -1] := base) &
|
||||
(i := 1 to *poles) do # read from the bottom of the poles
|
||||
if poles[i] > 0 then { # if there's a bead on the pole ...
|
||||
poles[i] -:= 1 # ... remove it
|
||||
X[j] +:= 1 # ... and add it in place
|
||||
}
|
||||
return X
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue