Question: Java: Documenting this method Please help me explain this code line by line by helping me document this method above the // TODO: document

Java: Documenting this method

Please help me explain this code line by line by helping me document this method above the "// TODO: document this method" in the code below for countingSort and radixSort. I already implemented the method, but just need help documenting the method for countingSort and radixSort line by line.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class PA2 {

// TODO: document this method public static int[] countingSort(int[] a) { //TODO: implement this method if (a.length == 0) { return a; }

int max = a[0];

for (int i = 1; i < a.length; i++) if (a[i] > max) max = a[i];

int[] count = new int[max > a.length ? max + 1 : a.length + 1]; int[] sorted = new int[a.length];

for (int element = 0; element < a.length; element++) count[a[element]]++;

for (int i = 0, j = 0; i < count.length; i++) { while (count[i] != 0) { sorted[j] = i; count[i]--; j++;

} }

return sorted; }

// TODO: document this method public static int[] radixSort(int[] a) { // TODO: implement this method if (a.length == 0) { return a; }

int max = a[0]; int num = 1;

int[] arr2 = new int[1000]; // Array2 size of 1000

for (int i = 1; i < a.length; i++) { if (a[i] > max) { max = a[i]; } }

// System.out.println("hello"); // int d = String.valueOf(max).length();

while (max / num > 0) {

int[] arr = new int[10];

for (int i = 0; i < a.length; i++) arr[((a[i] / num) % 10)]++;

for (int i = 1; i < arr.length; i++) arr[i] += arr[i - 1];

for (int i = a.length - 1; i >= 0; i--) arr2[--arr[(a[i] / num) % 10]] = a[i];

for (int i = 0; i < a.length; i++) a[i] = arr2[i];

num *= 10; }

return a; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!