# Help with parallelism, pointers, and C++, array not sort like wanted

Question:

I’m trying to work with pointers and references, this program is for me to test out radix sort using parallelism. However, it’s only sort the 1st half of the array.

``````#include <iostream>

using namespace std;

void rSort(int *a, int size, int b[]){
//sort from 1st digit
int d = 1;
int m = b[0];
//find max
for (int i = 0; i < size; i++)
{
if (b[i] > m)
{
m = b[i];
}
}
while (m/d > 0){
int count[10] = {0};
for (int i = 0; i < size; i++){
count[(a[i]/d)%10]++;
}
for (int i = 1; i < 10; i++){
count[i] += count[i-1];
}
for (int i = size-1; i >= 0; i--){
b[count[(a[i]/d)%10] - 1] = a[i];
count[(a[i]/d)%10]--;
}
for (int i = 0; i < size; i++){
a[i] = b[i];
}
d *= 10;
}
}

int main(){
int a[10] = {0,3,2,6,1,9,7,5,8,4};
int size = 10/2;
int start;
int end;
//partition the array A into 2, and call to sort them individually
for (int i = 0; i < 2; i++){
int b[size];
start = i*size;
end = start+size;
for (int j = start; j < end; j++){
b[j] = a[j];
}
rSort(a, size, b);
}
//gonna work on the merge later
for (int i  = 0; i < 10; i++)
cout<< a[i] << " ";
return 0;
}

``````

**Output: **

``````0 1 2 3 6 9 7 5 8 4
``````

The first thing that jumps out at me is that you are setting size to half the length of the array. My suggestion in the first instance is to output the values of all variables as the code runs to see what is happening. Maybe the `while` loop is causing the issue?