Menu
Coddy logo textTech

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 icon

Challenge

Medium

Now 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;
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Radix Sort - DSA Series