Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a JAVA HA230-Radix Sort Animation Compatibility Mode Review Viow JAVA HA23.0: Ra

ID: 3911675 • Letter: A

Question

a JAVA HA230-Radix Sort Animation Compatibility Mode Review Viow JAVA HA23.0: Radix Sort Animation Write a program (RadixSortAnimation.java) that animates the radix sort algorithm. Create an array that consists of 20 random integers from 0 to 999, inclusive. The array elements are displayed, as shown in Figure 0. Clicking the Step button causes the program to place a number in a bucket. The number that has just been placed is displayed in red, as shown in Figure 1. Once all the numbers are placed in the buckets, clicking the Step button collects all the numbers from the buckets and moves them back to the array, as shown in Figure 2. When the algorithm is finished, clicking the Step button displays a message to inform the user, as shown in Figure 3. Clicking the Reset button creates a new random array for a new start Radix Sort Animation 368 460 38| 464 165 299 1 97 956 327 612 615 815 | 849 89) 51 243 655 599 bucket/0) bucke:[A] bucket2] bucket3] bucket!4) bucket5) bucker[5) bucketT) buckert 8) bucketl9) Step Reset Figure 0 a Radix Sort Animation 68 460 889 463 253 29913 972 953827 632 63 813 849 8903153 243 55 599 12 893 464 65 615 815 956 327 365 299 849 460 972

Explanation / Answer

import java.io.*;

import java.util.*;

class Radix {

//Array [] values

    static int getMax(int arr[], int n)

    {

        int mx = arr[0];

        for (int i = 1; i < n; i++)

            if (arr[i] > mx)

                mx = arr[i];

        return mx;

    }

//function to do array[] methods

    static void countSort(int arr[], int n, int exp)

    {

        int output[] = new int[n]; // output array

        int i;

        int count[] = new int[10];

        Arrays.fill(count,0);

        // count values to store

        for (i = 0; i < n; i++)

            count[ (arr[i]/exp)%10 ]++;

        for (i = 1; i < 10; i++)

            count[i] += count[i - 1];

        for (i = n - 1; i >= 0; i--)

        {

            output[count[ (arr[i]/exp)%10 ] - 1] = arr[i];

            count[ (arr[i]/exp)%10 ]--;

        }

        for (i = 0; i < n; i++)

            arr[i] = output[i];

    }

static void radixsort(int arr[], int n)

    {

        int m = getMax(arr, n);     

   for (int exp = 1; m/exp > 0; exp *= 10)

            countSort(arr, n, exp);

    }

    static void print(int arr[], int n)

    {

        for (int i=0; i<n; i++)

            System.out.print(arr[i]+" ");

    }

    public static void main (String[] args)

    {

        int arr[] = {170, 45, 75, 90, 802, 24, 2, 66};

        int n = arr.length;

        radixsort(arr, n);

        print(arr, n);

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote