Implementation (Part 2)
Lesson 6 of 9 in Coddy's Counting Sort - DSA Series course.
Now we count every value and rebuild the array in order.
Challenge
EasyNow put it all together into the full algorithm.
Write a function named countingSort that takes an array of non-negative integers and returns it sorted in ascending order.
Find the largest value, build a count array of size max + 1, tally every element, then rebuild the result by writing each value v into the output count[v] times, from smallest to largest.
Reuse the counting idea from the previous lesson.
Try it yourself
#include <stdlib.h>
int* countingSort(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 Counting Sort - DSA Series
2The Algorithm
How it works?Pseudo CodeImplementation (Part 1)Implementation (Part 2)