June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,37 @@
|
|||
import extensions.
|
||||
import system'routines.
|
||||
|
||||
extension $op
|
||||
{
|
||||
countingSort
|
||||
= self clone; countingSort(self minimalMember, self maximalMember).
|
||||
|
||||
countingSort int:min int:max
|
||||
[
|
||||
array<int> count := int<>(max - min + 1).
|
||||
int z := 0.
|
||||
|
||||
count populate(:i)<int>(0).
|
||||
|
||||
0 till(self length) do(:i) [ count[self[i] - min] += 1 ].
|
||||
|
||||
min to:max do(:i)
|
||||
[
|
||||
while (count[i - min] > 0)
|
||||
[
|
||||
self[z] := i.
|
||||
z += 1.
|
||||
|
||||
count[i - min] -= 1.
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var list := 0 to:10 repeat(:i)(randomGenerator eval(10)); toArray.
|
||||
|
||||
console printLine("before:", list).
|
||||
console printLine("after :", list countingSort).
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue