Implementation (Part 2)
Lesson 6 of 9 in Coddy's Radix Sort - DSA Series course.
Now we run the per-digit counting sort once for each digit position.
Challenge
MediumNow put it all together into the full algorithm.
Write a function named radixSort that takes an array of non-negative integers and returns it sorted in ascending order, using your per-digit counting sort once for each digit position.
Find the largest value, then loop with exp = 1, 10, 100, ... As long as there is still a digit at that place value, run countingSortByDigit and multiply exp by 10.
Reuse the counting sort from the previous lesson as a helper.
Try it yourself
#include <stdlib.h>
int* radixSort(int* arr, int arr_size, int* returnSize) {
// Write code here
*returnSize = arr_size;
return arr;
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Radix Sort - DSA Series
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)