1. Member Join Date
Mar 2013
Posts
1
Rep Power
0

## Learning Radix sort

I understand how radix sort works. You take a set of numbers and your sort by the lowest part of each number. So if you have 345 236 and 786 you would sort by 1's position, 10's position, and 100's position. My book explains all this easily enough. It does not however give any explanation of how you about sorting a digit then the next and so on. I am writing a radix sort that uses counting sort as the stable sort and I am not completely sure how to maintain which digit position during sort. I have the counting sort working fine but I am not sure how to use the radix sort and then implement that into the counting sort

Java Code:
```public static int[] radixSort(int[] A, int d){
int[] B = new int[A.length];
int[] C = new int[d + 1];
for(int i = 0; i < d; i++){
for(int j = 0; j <= d; j++){
C[j] = 0;
}
for(int j = 0; j < A.length; j++){
C[A[j]] = C[A[j]] + 1;
}
for(int j = 1; j <= d; j++){
C[j] = C[j] + C[j-1];
}
for(int j = A.length - 1; j >= 0; j--){
B[C[A[j]]-1] = A[j];
C[A[j]] = C[A[j]] - 1;
}
}
return B;
}```  Reply With Quote

2. ## Re: Learning Radix sort  Reply With Quote

java, radixsort 