Question: Write a java Radix Sort from python pseudocode below: def radix_sort(array, base=10): def list_to_buckets(array, base, iteration): buckets = [[] for _ in range(base)] for number
Write a java Radix Sort from python pseudocode below:
def radix_sort(array, base=10): def list_to_buckets(array, base, iteration): buckets = [[] for _ in range(base)] for number in array: # Isolate the base-digit from the number digit = (number // (base ** iteration)) % base # Drop the number into the correct bucket buckets[digit].append(number) return buckets
def buckets_to_list(buckets): return [x for bucket in buckets for x in bucket]
maxval = max(array)
it = 0 # Iterate, sorting the array by each base-digit while base ** it <= maxval: array = buckets_to_list(list_to_buckets(array, base, it)) it += 1
return array
* array should be [14, 25, 120, 92, 75, 58, 72, 49, 38, 81, 66] in Main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
