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
Cost, time, knowledge are examples of
Katena32 [7]
They are examples of constraints.
8 0
3 years ago
Which of the following things would you access from the Program &amp; Courses page? Course descriptions Tutorial videos Account
Paraphin [41]

Course descriptions.

5 0
3 years ago
Express the worst case run time of these pseudo-code functions as summations. You do not need to simplify the summations. a) fun
ser-zykov [4K]

Answer:

The answer is "O(n2)"

Explanation:

The worst case is the method that requires so many steps if possible with compiled code sized n. It means the case is also the feature, that achieves an average amount of steps in n component entry information.

  • In the given code, The total of n integers lists is O(n), which is used in finding complexity.
  • Therefore, O(n)+O(n-1)+ .... +O(1)=O(n2) will also be a general complexity throughout the search and deletion of n minimum elements from the list.
5 0
3 years ago
Why can't I register for Brainly?? I've been trying for months, too! I've noticed this question has been asked so many times, bu
Alenkasestr [34]

Answer:

Just click view profile and go to preferences

Heres a screenshot :

4 0
3 years ago
guys im so heartbroken. so i quit art. heres my laST piece of art i did. it took me a month. im burning it tonight. i quit art..
Helga [31]

Answer:

Ok

hsjsbsjwiqnsbsjsowiwi

5 0
3 years ago
Read 2 more answers
Other questions:
  • Los antivirus no son infalibles y en ocasiones pueden darnos :
    10·1 answer
  • What is a Software Quality Assurance Audit?
    12·1 answer
  • Briefly explain the following terms and concepts:
    8·2 answers
  • Describe a time when you influenced someone else’s knowledge around technology, whether it be an app, a new gadget, etc. What di
    14·1 answer
  • Why is know app downloading in my android phone even if I have 900 MB ???
    8·2 answers
  • Consider the algorithm for determining whether a sequence of parentheses is balanced (has correct nesting). The pseudo code for
    10·1 answer
  • Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times
    5·1 answer
  • What are the steps involed in accepting all the changes in a document?
    8·1 answer
  • How to make classs constructer java.
    14·1 answer
  • What network security tool, usually included with Kali Linux, allows a user to ping multiple IP addresses
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!