Answer to Question #262878 in Java | JSP | JSF for masedi moncho

Question #262878

Complete the array representing the buckets for a bucket sort for the following array. This is done using Integers and the key is the value. The value that you have to enter is the amount of elements in each list. An empty list will have a value of 0. A list with 3 elements will have a value of 3.



4 3 6 4 3 4 5 6 3 5 6 5




0 1 2 3 4 5 6 7 8 9


Blank 1. Fill in the blank, read surrounding text.


Blank 2. Fill in the blank, read surrounding text.


Blank 3. Fill in the blank, read surrounding text.


Blank 4. Fill in the blank, read surrounding text.


Blank 5. Fill in the blank, read surrounding text.


Blank 6. Fill in the blank, read surrounding text.


Blank 7. Fill in the blank, read surrounding text.


Blank 8. Fill in the blank, read surrounding text.


Blank 9. Fill in the blank, read surrounding text.


Blank 10. Fill in the blank, read surrounding text.


1
Expert's answer
2021-11-10T11:53:33-0500
import java.util.*;
import java.util.Collections;
 
class Main {
 
   
    static void bucket_Sort(float array[], int size)
    {
        if (size <= 0)
            return;
 
       
        Vector<Float>[] buckets = new Vector[size];
 
        for (int i = 0; i < size; i++) {
            buckets[i] = new Vector<Float>();
        }
 
        
        for (int i = 0; i < size; i++) {
            float c = array[i] * size;
            buckets[(int)c].add(array[i]);
        }
 
       
        for (int i = 0; i < size; i++) {
            Collections.sort(buckets[i]);
        }
 
        
        int count = 0;
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < buckets[i].size(); j++) {
                array[count++] = buckets[i].get(j);
            }
        }
    }
 
    
    public static void main(String args[])
    {
        float array[] = { (float)0.822, (float)0.522,
                        (float)0.626, (float)0.1555,
                        (float)0.667, (float)0.9988 };
 
        int n = array.length;
        bucket_Sort(array, n);
 
        System.out.println("Final sorted array is ");
        for (float auto : array) {
            System.out.print(auto + " ");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS