File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ Community (college) maintained list of Algorithms and Data Structures implementa
42
42
| [ Prims] ( https://en.wikipedia.org/wiki/Prim%27s_algorithm ) | [ :white_check_mark : ] ( prims/prims.c ) | | [ :white_check_mark : ] ( prims/Prims.java ) | | [ :white_check_mark : ] ( prims/prims.go ) | [ :white_check_mark : ] ( prims/prims.js ) | |
43
43
| [ Quick Select] ( https://en.wikipedia.org/wiki/Quickselect ) | [ :white_check_mark : ] ( quick_select/quick_select.c ) | | [ :white_check_mark : ] ( quick_select/QuickSelect.java ) | [ :white_check_mark : ] ( quick_select/quick_select.py ) | | | |
44
44
| [ Quicksort] ( https://en.wikipedia.org/wiki/Quicksort ) | [ :white_check_mark : ] ( quick_sort/quicksort.c ) | | [ :white_check_mark : ] ( quick_sort/QuickSort.java ) | [ :white_check_mark : ] ( quick_sort/quick_sort.py ) | [ :white_check_mark : ] ( quick_sort/quick_sort.go ) | [ :white_check_mark : ] ( quick_sort/quickSort.js ) | [ :white_check_mark : ] ( quick_sort/QuickSort.cs ) |
45
- | [ Radix Sort] ( http://www.geeksforgeeks.org/radix-sort/ ) | | | [ :white_check_mark : ] ( radix_sort/RadixSort.java ) | [ :white_check_mark : ] ( radix_sort/radix_sort.py ) | | | |
45
+ | [ Radix Sort] ( http://www.geeksforgeeks.org/radix-sort/ ) | [ : white_check_mark : ] ( radix_sort/radix_sort.c ) | | [ :white_check_mark : ] ( radix_sort/RadixSort.java ) | [ :white_check_mark : ] ( radix_sort/radix_sort.py ) | | | |
46
46
| [ Rod Cutting Problem] ( http://www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/ ) | [ :white_check_mark : ] ( rod_cutting_problem/rod_cutting.c ) | | [ :white_check_mark : ] ( rod_cutting_problem/RodCutting.java ) | [ :white_check_mark : ] ( rod_cutting_problem/rod_cutting.py ) | [ :white_check_mark : ] ( rod_cutting_problem/rod_cutting.go ) | [ :white_check_mark : ] ( rod_cutting_problem/rodCuttingProblem.js ) | |
47
47
| [ Shell Sort] ( https://en.wikipedia.org/wiki/Shellsort ) | | [ :white_check_mark : ] ( shell_sort/ShellSort.cpp ) | [ :white_check_mark : ] ( shell_sort/ShellSort.java ) | [ :white_check_mark : ] ( /shell_sort/shell_sort.py ) | [ :white_check_mark : ] ( shell_sort/shell_sort.go ) | [ :white_check_mark : ] ( shell_sort/shellSort.js ) | [ :white_check_mark : ] ( shell_sort/ShellSort.cs ) |
48
48
| [ Sieve of Eratosthenes] ( https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes ) | [ :white_check_mark : ] ( sieve_of_eratosthenes/sieveOfEratosthenes.c ) | | [ :white_check_mark : ] ( sieve_of_eratosthenes/SieveOfEratosthenes.java ) | [ :white_check_mark : ] ( sieve_of_eratosthenes/sieve_of_eratosthenes.py ) | [ :white_check_mark : ] ( sieve_of_eratosthenes/sieve_of_eratosthenes.go ) | [ :white_check_mark : ] ( sieve_of_eratosthenes/sieveOfEratosthenes.js ) | |
Original file line number Diff line number Diff line change
1
+ #include "stdio.h"
2
+ #include <time.h>
3
+ #include <stdlib.h>
4
+
5
+ /*
6
+ * Returns maximum number in an array
7
+ * @a array pointer
8
+ * @n number of elements in the array
9
+ */
10
+ int max (int * a , int n ) {
11
+ int max = a [0 ];
12
+ for (int i = 1 ; i < n ; i ++ ) {
13
+ if (a [i ] > max ) {
14
+ max = a [i ];
15
+ }
16
+ }
17
+ return max ;
18
+ }
19
+
20
+ /*
21
+ * Performs Radix Sort on a given array
22
+ * @a array pointer
23
+ * @n number of elements in the array
24
+ */
25
+ void radix_sort (int * a , int n ) {
26
+ int m = max (a , n );
27
+ int b [10 ] = {0 };
28
+
29
+ for (int exp = 1 ; m / exp > 0 ; exp *=10 ) {
30
+ int bucket [10 ] = {0 };
31
+
32
+ for (int i = 0 ; i < n ; i ++ )
33
+ bucket [(a [i ] / exp ) % 10 ]++ ;
34
+ for (int i = 1 ; i < n ; i ++ )
35
+ bucket [i ] += bucket [i - 1 ];
36
+ for (int i = n - 1 ; i >= 0 ; i -- )
37
+ b [-- bucket [(a [i ] / exp ) % 10 ]] = a [i ];
38
+
39
+ for (int i = 0 ; i < n ; i ++ )
40
+ a [i ] = b [i ];
41
+ }
42
+ }
43
+
44
+ int main () {
45
+ srand (time (NULL ));
46
+ int n = 10 ;
47
+
48
+ int test_array [n ];
49
+ for (int i = 0 ; i < n ; i ++ ) {
50
+ test_array [i ] = rand () % 1000 ;
51
+ }
52
+
53
+ radix_sort (test_array , n );
54
+ for (int i = 0 ; i < n ; i ++ ) {
55
+ printf ("%d " , test_array [i ]);
56
+ }
57
+ printf ("\n" );
58
+ return 0 ;
59
+ }
You can’t perform that action at this time.
0 commit comments