Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
|||
List do(
|
||||
countingSort := method(min, max,
|
||||
count := list() setSize(max - min + 1) mapInPlace(0)
|
||||
foreach(x,
|
||||
count atPut(x - min, count at(x - min) + 1)
|
||||
)
|
||||
|
||||
j := 0
|
||||
for(i, min, max,
|
||||
while(count at(i - min) > 0,
|
||||
atPut(j, i)
|
||||
count atPut(i - min, at(i - min) - 1)
|
||||
j = j + 1
|
||||
)
|
||||
)
|
||||
self)
|
||||
|
||||
countingSortInPlace := method(
|
||||
countingSort(min, max)
|
||||
)
|
||||
)
|
||||
|
||||
l := list(2, 3, -4, 5, 1)
|
||||
l countingSortInPlace println # ==> list(-4, 1, 2, 3, 5)
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
List do(
|
||||
fill := method(x, size,
|
||||
/* Resizes list to a given size and fills it with a given value. */
|
||||
setSize(size) mapInPlace(x)
|
||||
)
|
||||
|
||||
countingSort := method(min, max,
|
||||
count := list() fill(0, max - min + 1)
|
||||
foreach(x,
|
||||
count atPut(x - min, count at(x - min) + 1)
|
||||
)
|
||||
|
||||
return count map(i, x, list() fill(i + min, x)) \
|
||||
prepend(list()) reduce(xs, x, xs appendSeq(x))
|
||||
)
|
||||
|
||||
countingSortInPlace := method(
|
||||
copy(countingSort(min, max))
|
||||
)
|
||||
)
|
||||
|
||||
l := list(2, 3, -4, 5, 1)
|
||||
l countingSortInPlace println # ==> list(-4, 1, 2, 3, 5)
|
||||
Loading…
Add table
Add a link
Reference in a new issue