Sorting algorithms/Radix sort: Difference between revisions

m
m (→‎{{header|Tailspin}}: syntax update)
Line 2,587:
templates radixsort@{base:}
templates bucketize
def value: $it;
$it / $@radixsort.digit -> #
<0 ?($value <0..>)>
..|@radixsort.positives: $value;
Line 2,594:
..|@radixsort.negatives(-1): $value;
<>
def bucket: $it mod $base -> (<?($value<0..>)> $it + 1 ! <0> $base ! <> $it !);
..|@radixsort.buckets($bucket): $value;
@radixsort.done: 0;
Line 2,600:
// Negatives get completed in wrong length-order, we need to collect by length and correct at the end
@: { done: 1, digit: 1, positives: [], negatives: [[]], buckets: [1..$base -> []]};
$it... -> bucketize -> void!VOID
$@.done -> #
<1>
Line 2,608:
..|@: {done: 1, digit: $@.digit * $base, buckets:[1..$base -> []]};
..|@.negatives: [];
$previous... ... -> bucketize -> void!VOID
$@.done -> #
end radixsort
 
[170, 45, 75, 91, 90, 92, 802, 24, 2, 66] -> radixsort@{base:10} -> !OUT::write
'
Anonymous user