Explain this radix sort method line by line adding comments on what each line do
ID: 3552974 • Letter: E
Question
Explain this radix sort method line by line adding comments on what each line does
public static void radixsort( int[] a)
{
int i;
int m = a[0];
int ex = 1;
int n = a.length;
int[] b = new int[1000];
for (i = 1; i < n; i++)
if (a[i] > m)
m = a[i];
while (m / ex > 0)
{
int[] bucket = new int[1000];
for (i = 0; i < n; i++)
bucket[(a[i] / ex) % 10]++;
for (i = 1; i < 10; i++)
bucket[i] += bucket[i - 1];
for (i = n - 1; i >= 0; i--)
b[--bucket[(a[i] / ex) % 10]] = a[i];
for (i = 0; i < n; i++)
a[i] = b[i];
ex=ex*10;
}
}
Explanation / Answer
Radix sort Algorithm:
Do following for each digit i where i varies from least significant digit to the most significant digit.
Sort input array using counting sort (or any stable sort) according to the i
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.