diff --git a/algorithms/C/README.md b/algorithms/C/README.md index da034e96..6caf86ae 100644 --- a/algorithms/C/README.md +++ b/algorithms/C/README.md @@ -53,6 +53,7 @@ - [Selection Sort](sorting/selection-sort.c) - [Quick Sort](sorting/quick-sort.c) - [Shell Sort](sorting/shell-sort.c) +- [Radix Sort](sorting/radix-sort.c) ## Strings diff --git a/algorithms/C/sorting/radix-sort.c b/algorithms/C/sorting/radix-sort.c new file mode 100644 index 00000000..6a9e3069 --- /dev/null +++ b/algorithms/C/sorting/radix-sort.c @@ -0,0 +1,66 @@ +#include + + +int get_max( int arr[], int n){ + + int myMax = -1 ; + for(int i=0; i myMax)myMax = arr[i] ; + } + + return myMax ; +} + +void count_sort(int arr[], int n, int digit){ + int count[10] = {0} ; + int *sorted ; + sorted = (int*)malloc(n * sizeof(int)); + + for(int i=0; i=0; i--){ + sorted[--count[(arr[i]/digit)%10]] = arr[i] ; + } + + for(int i=0; i