Question

I've read an implementation of radix sort that works with int data types that are less than ten i.e. they consist of one sig-fig in the one's place. (e.g. 1, 0, 3, 4, 9,... just to be clear). This implementation is not too difficult, but what about numbers greater than ten? How do you compare just the digits in the one's place on the first pass, then the digits in the ten's place on the second pass, and so on without explicitly converting to elements of the array to strings or char types. (or is this simply necessary?)

Was it helpful?

Solution

You can always pull the nth digit as v/(10**(n-1)) % 10.

Going from a single digit radix sort to a multi-digit general sorter is not trivial. Depending on the order you process the digits in you either end up tracking group boundaries or have to use a "stable" variant.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top