Question
Makefie RadixSorter.class: RadixSorter.java javac RadixSorter.java runProgram: RadixSorter.class java RadixSorter clean: rm *.class RadixSorter.java public class RadixSorter { /** * TODO: Execute radix sort in-place on
Makefie
RadixSorter.class: RadixSorter.java javac RadixSorter.java
runProgram: RadixSorter.class java RadixSorter
clean: rm *.class
RadixSorter.java
public class RadixSorter {
/** * TODO: Execute radix sort in-place on the given array. **/ void radixSort(int array[]) { return ; }
/** * Does counting sort on the given array for the given digit. * digit is 10^(digit to sort by) **/ void countingSort(int array[], int digit) { // Array to temporarily store sorted array int output[] = new int[array.length]; // Stores how many elements we have of each digit int count[] = new int[10];
// Count how many elements we have of each digit for (int num : array) { count[(num / digit) % 10]++; }
// Count how many elements we have of each digit less than or equal to itself for (int i = 1; i < 10; i++) { count[i] += count[i - 1]; }
// Sort the array by digit for (int i = array.length - 1; i >= 0; i--) { int num = (array[i] / digit) % 10; output[count[num] - 1] = array[i]; count[num]--; }
// Copy output array into original array for (int i = 0; i < array.length; i++) { array[i] = output[i]; } }
/** * Get the maximal element of a given array **/ int getMax(int array[]) { int max = array[0]; for (int num : array) {
max = num > max ? num : max; } return max; }
public static void main(String[] args) { System.out.println("This is RadixSorter"); } }
SortPrinter.java
import java.util.Arrays;
/** * Class that prints out a an array of arrays, each one sorted by RadixSorter. **/ public class SortPrinter { public static void main(String args[]) { RadixSorter sorter = new RadixSorter();
int[][] myArrays = { {5, 7, 3, 2, 8}, { 15, 5, 20, 12, 80, 49, 2} };
for (int[] arr : myArrays) { sorter.radixSort(arr); System.out.println(Arrays.toString(arr)); } } }
Please give me steps how to do these.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started