diff --git a/Sorting/README.md b/Sorting/README.md index 4e92ffc01..6baaa1fe1 100644 --- a/Sorting/README.md +++ b/Sorting/README.md @@ -11,6 +11,6 @@ | [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | [:heavy_check_mark:](Insertion%20Sort/C/insertion_sort.c) | [:heavy_check_mark:](Insertion%20Sort/C%2B%2B/insertion_sort.cpp) | [:heavy_check_mark:](Insertion%20Sort/Java/insertion_sort.java) | [:heavy_check_mark:](Insertion%20Sort/Python/insertion_sort.py) | [:heavy_check_mark:](Insertion%20Sort/Javascript/insertion_sort.js) | | [:heavy_check_mark:](Insertion%20Sort/Go/insertion_sort.go) | [:heavy_check_mark:](Insertion%20Sort/Ruby/insertion_sort.rb) | [:heavy_check_mark:](Insertion%20Sort/Rust/insertion_sort.rs) | | | [Merge Sort](https://en.wikipedia.org/wiki/Merge_sort) | [:heavy_check_mark:](Merge%20Sort/C/merge_sort.c) | [:heavy_check_mark:](Merge%20Sort/C%2B%2B/merge_sort.cpp) | [:heavy_check_mark:](Merge%20Sort/Java/merge_sort.java) | [:heavy_check_mark:](Merge%20Sort/Python/merge_sort.py) | [:heavy_check_mark:](Merge%20Sort/Javascript/merge_sort.js) | | | [:heavy_check_mark:](Merge%20Sort/Ruby/merge_sort.rb) | [:heavy_check_mark:](Merge%20Sort/Rust/merge-sort.rs) | [:heavy_check_mark:](Merge%20Sort/Swift/merge_sort.swift) | | [Quick Sort](https://en.wikipedia.org/wiki/Quick_sort) | [:heavy_check_mark:](quickSort/C/quick_sort.c) | [:heavy_check_mark:](quickSort/C%2B%2B/quick_sort.cpp) | [:heavy_check_mark:](quickSort/Java/quick_sort.java) | [:heavy_check_mark:](quickSort/python/quick_sort.py) | [:heavy_check_mark:](quickSort/Javascript/quick_sort.js) | [:heavy_check_mark:](quickSort/csharp/QuickSort.cs) | [:heavy_check_mark:](quickSort/Go/quick_sort.go) | [:heavy_check_mark:](quickSort/Ruby/quick_sort.rb) | [:heavy_check_mark:](quickSort/Rust/quick-sort.rs) | | -| [Radix Sort](https://en.wikipedia.org/wiki/Radix_sort) | | [:heavy_check_mark:](Radix%20Sort/C%2B%2B/radix_sort.cpp) | [:heavy_check_mark:](Radix%20Sort/Java/radix_sort.java) | [:heavy_check_mark:](Radix%20Sort/python/Radix_Sort.py) | | | [:heavy_check_mark:](Radix%20Sort/Go/radix_sort.go) | [:heavy_check_mark:](Radix%20Sort/Ruby/radixSort.rb) | | | +| [Radix Sort](https://en.wikipedia.org/wiki/Radix_sort) |[:heavy_check_mark:](Radix%20Sort/C/radix_sort.c) | [:heavy_check_mark:](Radix%20Sort/C%2B%2B/radix_sort.cpp) | [:heavy_check_mark:](Radix%20Sort/Java/radix_sort.java) | [:heavy_check_mark:](Radix%20Sort/python/Radix_Sort.py) | | | [:heavy_check_mark:](Radix%20Sort/Go/radix_sort.go) | [:heavy_check_mark:](Radix%20Sort/Ruby/radixSort.rb) | | | | [Selection Sort](https://en.wikipedia.org/wiki/Selection_sort) | [:heavy_check_mark:](Selection%20Sort/C/selection_sort.c) | [:heavy_check_mark:](Selection%20Sort/C%2B%2B/selection_sort.cpp) | [:heavy_check_mark:](Selection%20Sort/Java/selection_sort.java) | [:heavy_check_mark:](Selection%20Sort/Python/selection_sort.py) | [:heavy_check_mark:](Selection%20Sort/JavaScript/selectionSort.js) | | [:heavy_check_mark:](Selection%20Sort/Go/selection_sort.go) | [:heavy_check_mark:](Selection%20Sort/Ruby/selSort.rb) | [:heavy_check_mark:](Selection%20Sort/Rust/selection_sort.rs) | | | [Shell Sort](https://en.wikipedia.org/wiki/Shellsort) | [:heavy_check_mark:](ShellSort/c/shell_sort.c) | [:heavy_check_mark:](ShellSort/C%2B%2B/shell_sort.cpp) | [:heavy_check_mark:](ShellSort/Java/ShellSort.java) | [:heavy_check_mark:](ShellSort/python/shell_sort.py) | [:heavy_check_mark:](ShellSort/Javascript/shellsort.js) | [:heavy_check_mark:](ShellSort/csharp/ShellSort.cs) | | [:heavy_check_mark:](ShellSort/Ruby/shellSort.rb) | | | diff --git a/Sorting/Radix Sort/C/radix_sort.c b/Sorting/Radix Sort/C/radix_sort.c new file mode 100644 index 000000000..53dc0ec8f --- /dev/null +++ b/Sorting/Radix Sort/C/radix_sort.c @@ -0,0 +1,79 @@ +/*Radix sort +A sorting technique that sorts the elements by first grouping the individual digits of the same place value. +Then, sort the elements according to their increasing/decreasing order.*/ + +#include + +int max(int num[], int n); + +void radix_sort(int num[], int n); + +int main() +{ + int i, n; + printf("Enter the number of elements: "); + scanf("%d", &n); + int num[n]; + printf("Enter the numbers: "); + for (i = 0; i < n; i++) + { + scanf("%d", &num[i]); + } + radix_sort(num, n); + + printf("\n The Sorted list is : "); + + for (i = 0; i < n; i++) + printf("%d ", num[i]); + + printf("\n"); + return 0; +} + +int max(int num[], int n) +{ + int max = num[0]; + for (int i = 1; i < n; i++) + if (num[i] > max) + max = num[i]; + return max; +} + +void radix_sort(int num[], int n) +{ + int box[10][10], box_cnt[10]; + int i, j, k, r, NOP = 0, divisor = 1, lar, pass; + lar = max(num, n); + while (lar > 0) + { + NOP++; + lar /= 10; + } + for (pass = 0; pass < NOP; pass++) + { + for (i = 0; i < 10; i++) + { + box_cnt[i] = 0; + } + for (i = 0; i < n; i++) + { + r = (num[i] / divisor) % 10; + box[r][box_cnt[r]] = num[i]; + box_cnt[r] += 1; + } + i = 0; + for (k = 0; k < 10; k++) + { + for (j = 0; j < box_cnt[k]; j++) + { + num[i] = box[k][j]; + i++; + } + } + divisor *= 10; + printf("\tAfter Pass %d : ", pass + 1); + for (i = 0; i < n; i++) + printf("%d ", num[i]); + printf("\n"); + } +}