1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
valentinak56 [21]
4 years ago
13

Implement (in Java) the radixSort algorithm to sort in increasing order an array of integer positive keys. public void radixSort

(int arr[]) In your implementation you must consider that each key contains only even digits (0, 2, 4, 6, and 8). Your program must detect the case of odd digits in the keys, and, in this case, abort. Example #1:
Computers and Technology
1 answer:
Anestetic [448]4 years ago
8 0

Answer:

see explaination

Explanation:

import java.util.Scanner;

import java.util.ArrayList;

public class EvenRadixSort {

public static void main(String[] args) {

int n;

Scanner s=new Scanner(System.in);

System.out.println("enter number of elements to sort");

n=s.nextInt();

int[] arr=new int[n];

System.out.println("enter elements");

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

arr[i]=s.nextInt();

radixsort(arr);

System.out.print("after sorting\t ");

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

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

System.out.print("\n");

}

public static void radixsort(int[] arr) {

ArrayList<Integer>[] buckets = new ArrayList[10];

for (int i = 0; i < buckets.length; i++) {

buckets[i] = new ArrayList<Integer>();

}

// sort

boolean flag = false;

int tmp = -1, divisor = 1;

while (!flag) {

flag = true;

// split input between lists

for(int i=0;i<arr.length;i++) {

tmp = arr[i] / divisor;

if(tmp%2!=0){

System.out.println("odd digit in key");

System.exit(0);

}

buckets[tmp % 10].add(arr[i]);//insert number in certain bucket

if (flag && tmp > 0) {// check for divisor increment for next digit

flag = false;

}

}

// empty lists into input array arr

int a = 0;

for (int b = 0; b < 10; b=b+2) {

for (Integer i : buckets[b]) {

arr[a++] = i;

}

buckets[b].clear();

}

// move to next digit

divisor *= 10;

}

}

}

see attachment

You might be interested in
Sypherpk is good go sub 2 him
attashe74 [19]

Answer:

Ok

Explanation:

I will check him out, do you need anything else though?

4 0
3 years ago
Read 2 more answers
(01.05 LC)
andriy [413]
The answer is input! because the input is what the user enters, the output is what comes out from that, and the text and value aren’t related to the user
7 0
4 years ago
Read 2 more answers
The components of hardware include:
zlopas [31]

Answer:

A

Explanation:

Monitor, CPU, Disk Drives, Printer, Keyboard/mouse

5 0
3 years ago
Read 2 more answers
Immigrants are allowed to enter the country to work when they have a(n)
Roman55 [17]

Answer:

D. a Visa

Explanation:

4 0
3 years ago
What are the four different orchestral instrument families?
natka813 [3]

Answer:

Gutair

Violen

cello

Double Brass

Harp

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program that displays the following pattern: ..\.\* .\.\*** \.\***** ******* \.\***** .\.\*** ..\.\* That is, seven line
    8·1 answer
  • #We've started a recursive function below called #measure_string that should take in one string parameter, #myStr, and returns i
    5·1 answer
  • I have a question about a hotel tv: So I’ve brought my Nintendo Switch and my dock and plugged it in to the tv. Everything seems
    13·1 answer
  • PLEASE HELP!
    14·2 answers
  • Which function calls would provide the most helpful test of this function? Remember: With tests, you are attempting to figure ou
    5·1 answer
  • Taking a group of recipes and identifying the similarities is an example of _____.
    13·1 answer
  • A chemical mixture that is burned to produce thrust. (Jet engine homework)
    14·2 answers
  • One way to initiate a file download from a web page is to
    8·1 answer
  • In the following nested loop structure, which loop does the program EXIT first?
    6·1 answer
  • GIVING OUT BRAINLIEST AND I AM ALSO WARNING EVERYONE TO NOT ANSWER A BUNCH OF rubbish just to get the points!
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!