I have a task of making radix sort without 2d array or list "from scratch".
This is my code that works fine... untill you introduce numbers with 4 mor more digits.
int* radix( int n, int* a, int k) {
int m=10,temp;
int count[10],dest[n],*b=a;
for(int i=0;i<k;i++){
for(int j=0;j<m;j++) {count[j]=0;}
for(int j=0; j<n;j++) {count[((b[j]%((int)pow(10,i+1)))-(b[j]%((int)pow(10,i))))/(int)pow(10,i)]++;}
for(int j=m-1;j>=0;j--) {
temp=0;
for(int l=0;l<j;l++) {temp+=count[l];}
count[j]=temp;
}
for(int j=0; j<n;j++){
temp=((b[j]%((int)pow(10,i+1)))-(b[j]%((int)pow(10,i))))/(int)pow(10,i);
dest[count[temp]]=b[j];
count[temp]++;
}
for(int j=0;j<n;j++){ b[j]=dest[j];}
for(int j=0;j<n;j++){ cout<<b[j]<<' ';}
cout<<endl<<endl;
}
return b;
}
error occurs at dest[count[temp]]=b[j];
near the end.
I suspect that problems arise becose of relativly complex radix isolation.
I am too stuck in my head and dont see a possible solution.Plese help!