Skip to content
Snippets Groups Projects
Commit af067bae authored by Dinda Yora Islami's avatar Dinda Yora Islami
Browse files

edit radix

parent e40b12c1
No related merge requests found
...@@ -18,14 +18,14 @@ __device__ int getMax(int arr[], int n) ...@@ -18,14 +18,14 @@ __device__ int getMax(int arr[], int n)
// the digit represented by exp. // the digit represented by exp.
__device__ void countSort(int arr[], int n, int exp) __device__ void countSort(int arr[], int n, int exp)
{ {
int index = threadIdx.x; // int index = threadIdx.x;
int stride = blockDim.x; // int stride = blockDim.x;
int *output= (int*)malloc(sizeof(int)*n); // output array int *output= (int*)malloc(sizeof(int)*n); // output array
int i, count[10] = {0}; int i, count[10] = {0};
// Store count of occurrences in count[] // Store count of occurrences in count[]
for (i = index; i < n; i+=stride) for (i = 0; i < n; i++)
count[ (arr[i]/exp)%10 ]++; count[ (arr[i]/exp)%10 ]++;
// Change count[i] so that count[i] now contains actual // Change count[i] so that count[i] now contains actual
...@@ -34,7 +34,7 @@ __device__ void countSort(int arr[], int n, int exp) ...@@ -34,7 +34,7 @@ __device__ void countSort(int arr[], int n, int exp)
count[i] += count[i - 1]; count[i] += count[i - 1];
// Build the output array // Build the output array
for (i = n - 1; i >= index; i-=stride) for (i = n - 1; i >= 0; i--)
{ {
output[count[ (arr[i]/exp)%10 ] - 1] = arr[i]; output[count[ (arr[i]/exp)%10 ] - 1] = arr[i];
count[ (arr[i]/exp)%10 ]--; count[ (arr[i]/exp)%10 ]--;
...@@ -42,7 +42,7 @@ __device__ void countSort(int arr[], int n, int exp) ...@@ -42,7 +42,7 @@ __device__ void countSort(int arr[], int n, int exp)
// Copy the output array to arr[], so that arr[] now // Copy the output array to arr[], so that arr[] now
// contains sorted numbers according to current digit // contains sorted numbers according to current digit
for (i = index; i < n; i+=stride) for (i = 0; i < n; i++)
arr[i] = output[i]; arr[i] = output[i];
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment