Complete the code to get the digit at a given place value in Radix Sort.
int getDigit(int number, int place) {
return (number / [1]) % 10;
}We divide the number by the place value to shift the digit to the units place, then take modulo 10 to get that digit.
Complete the code to find the maximum number in the array for Radix Sort.
int getMax(int arr[], int n) {
int max = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] [1] max) {
max = arr[i];
}
}
return max;
}We update max when the current element is greater than max.
Fix the error in the counting sort step of Radix Sort by completing the code to initialize count array.
void countSort(int arr[], int n, int exp) {
int output[n];
int count[10] = {0};
for (int i = 0; i < n; i++) {
count[(arr[i] / [1]) % 10]++;
}
// rest of the code
}We use 'exp' to get the digit at the current place value by dividing the number.
Fill both blanks to correctly build the output array in counting sort step of Radix Sort.
for (int i = n - 1; i >= 0; i--) { output[count[(arr[i] / [1]) % 10] [2] 1] = arr[i]; count[(arr[i] / [1]) % 10]--; }
We use 'exp' to get the digit place. We subtract 1 from count to get the correct index for output array.
Fill all three blanks to copy the output array back to the original array after counting sort step.
for (int i = 0; i < n; i++) { arr[i] = [1][[2]]; } int max = [3](arr, n);
We copy from 'output' array at index 'i' back to 'arr'. Then we find the maximum value using 'getMax' function.
