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
Which payment type is best if you are trying to sick to a budget?
sleet_krkn [62]
That would be either cash or debit
5 0
4 years ago
i have a subscription under the name JaysonxH14, my email was never saved under the apple automatic password save. i cant figure
tekilochka [14]

Answer:

I think the best thing to do is try to remeber your emailor a email you use for your other accounts if that doesnt work contact apple support

Explanation:

5 0
3 years ago
Write a while loop that prints
Nana76 [90]

Answer:

The program to this question as follows:

Program:

#include <iostream> //defining header file

using namespace std;

int main() //defining main method

{

int squ=0,n=0; //defining variable

cout<<"Square between 0 to 100 :"; //message

while(n<100) //loop for calculate Square

{

n=squ*squ; //holing value in n variable

cout<<n<<" "; //print Square

squ++; //increment value by 1

}

cout<<endl; //for new line

n=1; //change the value of n

cout<<"Positive number, which is divisible by 10: "; //message

while (n< 100) //loop for check condition

{

if(n%10==0) //check value is divisible by 10

{

cout<<n<<" ";//print value

}

n++; //increment value of n by 1

}

cout<<endl; //for new line

cout<<"Powers of two less than n: "; //message

n=1; //holing value in n

while (n< 100) //loop for check condition

{

cout<<n<<" ";//print value

n=n*2; //calculate value

}

return 0;

}

Output:

Square between 0 to 100 :0 1 4 9 16 25 36 49 64 81 100  

Positive number, which is divisible by 10: 10 20 30 40 50 60 70 80 90  

Powers of two less than n: 1 2 4 8 16 32 64  

Explanation:

In the above program, two integer variable "squ and n" is defined, then three while loop is declared, which is used to calculate different values, that can be described as follows:

  • In the first while loop both "n and squ" variable is used, in which n is used for check range and "squ" is used to calculate the square between 1 to 100.
  • The second, while it is used to calculate the positive number, which is divisible by 10, in this only n variable is used, that calculates the value and check its range.
  • Then the last while loop is used which is used to calculate the double of the number, which is between 1 to 100 range.  
6 0
4 years ago
Assume that a finite number of resources of a single resource type must be managed. Processes may ask for a number of these reso
nevsk [136]
The answer may not be found
5 0
3 years ago
Impact of computer in society, using relevant examples​
Afina-wow [57]
Computers have changed the way we do things, from work, to school, and more. We use computers to work, play games, watch videos, and even fool around with Search engine Secrets. Examples include distance learning.Coronavirus changed the way we do things now. Hope this helps!
5 0
3 years ago
Other questions:
  • ____ are not associated with data from the database and are used to display such things as the report's title
    15·1 answer
  • List five characteristics of a series circuit
    9·1 answer
  • Which of these tools can best be used as a self assessment for career planning purposes
    12·1 answer
  • The appropriate length for an e-mail is about half the amount of text that will fit on an 8 1/2' by 11' page.
    11·2 answers
  • How do you know what memory to purchase for your computer?
    10·1 answer
  • You work in the educational software industry. Your boss asks you to give a brief lecture to other employees about the digital d
    7·2 answers
  • What is the output of the following program segment? int main() { int num = 5; cout &lt;&lt; num &lt;&lt;" "; change(num); cout
    8·1 answer
  • Which category of management information systems (MIS) combines the forecasting capability of decision support software with the
    12·1 answer
  • The formula =B2/A2 is inserted into cell C2. Which of the following is true when this formula is copied and pasted into cell C3?
    6·1 answer
  • Summarise all what you know about spss​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!