From 842cb215f5724088c1e712937b26de9bbe46db8b Mon Sep 17 00:00:00 2001 From: Arjun Singh Mann <37778385+arjunmann73@users.noreply.github.com> Date: Thu, 25 Jul 2019 17:16:00 +0800 Subject: [PATCH 1/5] Added Radix Sort --- sorting/radixsort.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 sorting/radixsort.c diff --git a/sorting/radixsort.c b/sorting/radixsort.c new file mode 100644 index 00000000..885616ed --- /dev/null +++ b/sorting/radixsort.c @@ -0,0 +1,43 @@ +#include +#include "swap.h" +#define range 10 + +void countsort(int arr[],int n,int place) +{ + int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9 + int output[n]; + for(i=0;i=0;i--) + { + output[freq[(arr[i]/place)%range]-1]=arr[i]; + freq[(arr[i]/place)%range]--; + } + for(i=0;i Date: Thu, 25 Jul 2019 13:17:50 +0400 Subject: [PATCH 2/5] Added MAX() function definition --- sorting/radixsort.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sorting/radixsort.c b/sorting/radixsort.c index 885616ed..8f274ede 100644 --- a/sorting/radixsort.c +++ b/sorting/radixsort.c @@ -1,7 +1,15 @@ #include -#include "swap.h" #define range 10 +int MAX(int ar[], int size1){ + int i, max1 = ar[0]; + for(i = 0; imax1) + max1 = ar[i]; + } + return max1; +} + void countsort(int arr[],int n,int place) { int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9 From e739f3530e56443f67f4a9acd75a1b80f123c27e Mon Sep 17 00:00:00 2001 From: Arjun Singh Mann <37778385+arjunmann73@users.noreply.github.com> Date: Thu, 25 Jul 2019 13:24:11 +0400 Subject: [PATCH 3/5] Update README.md Updated all available sorting functions present in the folder, Radix sort is pending to be added as a pull request. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index fd17f7de..e0d1ba88 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,12 @@ ## Sorting - BinaryInsertionSort - BubbleSort + - BucketSort - BogoSort + - CountingSort + - PartitionSort + - ShellSort + - RadixSort - InsertionSort - MergeSort - OtherBubbleSort From 585227967ac3967afe6bbd47d1a3bdfa7c45065c Mon Sep 17 00:00:00 2001 From: Arjun Singh Mann <37778385+arjunmann73@users.noreply.github.com> Date: Thu, 25 Jul 2019 13:36:23 +0400 Subject: [PATCH 4/5] Update README.md Updated available searching functions present in the searching folder. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index e0d1ba88..8afc7fde 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,13 @@ ## Searching + - Linear_Search - Binary_Search - Other_Binary_Search - Jump_Search + - Fibonacci_Search + - Interpolation_Search + - Modified_Binary_Search ## Sorting From b09f1d0f46e1266dd2083acfc07e156fbbc69e1c Mon Sep 17 00:00:00 2001 From: Arjun Singh Mann <37778385+arjunmann73@users.noreply.github.com> Date: Thu, 25 Jul 2019 17:13:41 +0400 Subject: [PATCH 5/5] Formatted RadixSort Code Formatted radix sort code similar to the other codes. --- sorting/radixsort.c | 71 +++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/sorting/radixsort.c b/sorting/radixsort.c index 8f274ede..6f0aa062 100644 --- a/sorting/radixsort.c +++ b/sorting/radixsort.c @@ -1,50 +1,83 @@ +//sorting of array list using Radix sort #include -#define range 10 -int MAX(int ar[], int size1){ - int i, max1 = ar[0]; - for(i = 0; imax1) - max1 = ar[i]; +#define range 10 // Range for integers is 10 as digits range from 0-9 + +// Utility function to get the maximum value in ar[] +int MAX(int ar[], int size){ + int i, max = ar[0]; + for(i = 0; imax) + max = ar[i]; } - return max1; + return max; } -void countsort(int arr[],int n,int place) +// Counting sort according to the digit represented by place +void countSort(int arr[],int n,int place) { - int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9 + int i,freq[range]={0}; int output[n]; + + // Store count of occurences in freq[] for(i=0;i=0;i--) { output[freq[(arr[i]/place)%range]-1]=arr[i]; freq[(arr[i]/place)%range]--; } + + // Copy the output array to arr[], so it contains numbers according to the current digit for(i=0;i