September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,12 @@
|
|||
fcn radixSort(ns){ // ints only, inplace, ns is mutable
|
||||
b:=(0).pump(20,List,List().copy); // 20 [empty] buckets: -10..10
|
||||
z:=ns.reduce(fcn(a,b){ a.abs().max(b.abs()) },0); // |max or min of input|
|
||||
m:=1;
|
||||
while(z){
|
||||
ns.apply2('wrap(n){ b[(n/m)%10 +10].append(n) }); // sort on right digit
|
||||
ns.clear(); b.pump(ns.extend); // slam buckets over src
|
||||
b.apply("clear"); // reset buckets
|
||||
m*=10; z/=10; // move sort digit left
|
||||
}
|
||||
ns
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
radixSort(T(170, 45, 75, 90, 802, 2, 24, 66)).println();
|
||||
radixSort(T(170, 45, 75, -90, -802, 24, 2, 66)).println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue