Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
; quicksort (lists, functional)
|
||||
|
||||
to small? :list
|
||||
output or [empty? :list] [empty? butfirst :list]
|
||||
end
|
||||
to quicksort :list
|
||||
if small? :list [output :list]
|
||||
localmake "pivot first :list
|
||||
output (sentence
|
||||
quicksort filter [? < :pivot] butfirst :list
|
||||
filter [? = :pivot] :list
|
||||
quicksort filter [? > :pivot] butfirst :list
|
||||
)
|
||||
end
|
||||
|
||||
show quicksort [1 3 5 7 9 8 6 4 2]
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
; quicksort (arrays, in-place)
|
||||
|
||||
to incr :name
|
||||
make :name (thing :name) + 1
|
||||
end
|
||||
to decr :name
|
||||
make :name (thing :name) - 1
|
||||
end
|
||||
to swap :i :j :a
|
||||
localmake "t item :i :a
|
||||
setitem :i :a item :j :a
|
||||
setitem :j :a :t
|
||||
end
|
||||
|
||||
to quick :a :low :high
|
||||
if :high <= :low [stop]
|
||||
localmake "l :low
|
||||
localmake "h :high
|
||||
localmake "pivot item ashift (:l + :h) -1 :a
|
||||
do.while [
|
||||
while [(item :l :a) < :pivot] [incr "l]
|
||||
while [(item :h :a) > :pivot] [decr "h]
|
||||
if :l <= :h [swap :l :h :a incr "l decr "h]
|
||||
] [:l <= :h]
|
||||
quick :a :low :h
|
||||
quick :a :l :high
|
||||
end
|
||||
to sort :a
|
||||
quick :a first :a count :a
|
||||
end
|
||||
|
||||
make "test {1 3 5 7 9 8 6 4 2}
|
||||
sort :test
|
||||
show :test
|
||||
Loading…
Add table
Add a link
Reference in a new issue