Created
July 2, 2016 02:43
-
-
Save raunaqbn/fe135f0158b8dec5112bb6df45692545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void countSort(int* arr,int size, int exp) | |
{ | |
int output[size]; | |
int count[10]; | |
for(int i=0; i<size; i++) | |
count[(arr[i]/exp)%10]++; | |
for(int i=1; i<10; i++) | |
count[i] += count[i-1]; | |
for(int i=0; i<size; i++) | |
{ | |
output[count[(arr[i]/exp)%10]-1]= arr[i]; | |
count[(arr[i]/exp)%10]--; | |
} | |
memcpy(arr,output,size); | |
} | |
void radixSort(int* arr,int size) | |
{ | |
// find largest value in array to get max no of digits | |
int max = max(arr,n); | |
for (int exp=1; max/exp > 0; exp*=10) | |
countSort(arr,size,exp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment