How to resolve the algorithm Sorting algorithms/Radix sort step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sorting algorithms/Radix sort step by step in the zkl programming language
Table of Contents
Problem Statement
Sort an integer array with the radix sort algorithm. The primary purpose is to complete the characterization of sort algorithms task.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sorting algorithms/Radix sort step by step in the zkl programming language
Source code in the zkl programming language
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
}
radixSort(T(170, 45, 75, 90, 802, 2, 24, 66)).println();
radixSort(T(170, 45, 75, -90, -802, 24, 2, 66)).println();
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Swift programming language
You may also check:How to resolve the algorithm Letter frequency step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Spiral matrix step by step in the Visual Basic programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the Fortran programming language
You may also check:How to resolve the algorithm Count in octal step by step in the Simula programming language