java bucket sort
Java
public static int[] bucketSort(int[] a) {
Queue<Integer>[] buckets = fillBuckets(a);
int[] sorted = readBuckets(buckets);
return sorted;
}
public static Queue<Integer>[] fillBuckets(int[] array) {
if(array.length == 0){
Queue<Integer>[] r = new Queue[0];
return r;
}
int vmin = array[0];
int vmax = array[0];
for(int i = 0; i < array.length; i++){
if(array[i] > vmax){
vmax = array[i];
}
if(array[i] < vmin){
vmin = array[i];
}
}
Queue<Integer>[] buckets = new Queue[vmax - vmin + 1];
for(int i = 0; i < buckets.length; i++){
buckets[i] = new LinkedList<Integer>();
}
for(int i = 0; i < array.length; i++){
buckets[array[i] - vmin].add(array[i]);
}
return buckets;
}
public static int[] readBuckets(Queue<Integer>[] buckets) {
if(buckets.length == 0){
int[] e = new int[0];
return e;
}
ArrayList<Integer> a = new ArrayList<Integer>();
for(int i = 0 ; i < buckets.length; i++){
while(buckets[i].peek() != null){
a.add(buckets[i].remove());
}
}
int[] result = new int[a.size()];
for(int i = 0; i < a.size(); i++){
result[i] = a.get(i);
}
return result;
}
Also in Java:
- Title
- thread sleep java
- Category
- Java
- Title
- java divisible by operator
- Category
- Java
- Title
- how to close a jframe in java with an if statement
- Category
- Java
- Title
- how to make javafx full screen default
- Category
- Java
- Title
- threadsafe singleton pattern in java
- Category
- Java
- Title
- string a int java
- Category
- Java
- Title
- break for loop java
- Category
- Java
- Title
- how to use for loop for array in java
- Category
- Java
- Title
- Error executing Maven. java.io.FileNotFoundException: The specified user settings file does not exist: /etc/java-8-openjdk
- Category
- Java
- Title
- detect tv remote keys andoid studio
- Category
- Java
- Title
- delete element from arraylist
- Category
- Java
- Title
- how to fix Index 2 out of bounds for length 2 when looping through an array in java
- Category
- Java
- Title
- faire un timer en java
- Category
- Java
- Title
- how to initialize array in java
- Category
- Java
- Title
- string reverse in java
- Category
- Java
- Title
- convert list of integer to array in java
- Category
- Java
- Title
- javafx polygon
- Category
- Java
- Title
- java substring
- Category
- Java
- Title
- how to end a program in an if statement java
- Category
- Java
- Title
- uppercase java
- Category
- Java
- Title
- java string array
- Category
- Java
- Title
- switch case java
- Category
- Java
- Title
- how to copy all files and subdirectories in directory in java
- Category
- Java
- Title
- java check if variable is set
- Category
- Java
- Title
- convert array of int to arraylist java
- Category
- Java
- Title
- java 8 add whole array to jsonarray
- Category
- Java
- Title
- close searchview android java
- Category
- Java
- Title
- java hashmap put
- Category
- Java
- Title
- HTTP FAILED: java.io.InterruptedIOException: interrupted
- Category
- Java
- Title
- java queue
- Category
- Java
- Title
- java execute for cycle parallel thread
- Category
- Java
- Title
- mkyong restful web services spring boot examples post
- Category
- Java
- Title
- how to get the dimensions of a 2d array in java
- Category
- Java
- Title
- android studio clear views of layout
- Category
- Java
- Title
- how to print something in java
- Category
- Java
- Title
- java int
- Category
- Java
- Title
- jquery set data attribute value
- Category
- Java
- Title
- Java how to handle HTTP GET request after establishing TCP connection
- Category
- Java
- Title
- if statement java
- Category
- Java
- Title
- loop while in java
- Category
- Java
- Title
- init cap java
- Category
- Java
- Title
- java pass arraylist by value
- Category
- Java
- Title
- function in java
- Category
- Java
- Title
- java for in loop
- Category
- Java
- Title
- java projects
- Category
- Java
- Title
- changing double space to single in java script
- Category
- Java
- Title
- Linked List implementation
- Category
- Java
- Title
- how to declare list of object in java as constant
- Category
- Java
- Title
- how get started with LWJGL 3
- Category
- Java
- Title
- java replace all xml decoding
- Category
- Java
- Title
- java 8 group a collections by 2 property
- Category
- Java
- Title
- print out value java
- Category
- Java
- Title
- write file java
- Category
- Java
- Title
- eliminar fila jtable java
- Category
- Java
- Title
- Manifest merger failed androidx
- Category
- Java
- Title
- java comments
- Category
- Java
- Title
- exponents java
- Category
- Java
- Title
- iterate over map keys java
- Category
- Java
- Title
- Caused by: java.lang.NumberFormatException: Invalid int: ""
- Category
- Java
- Title
- java return new instance of generic type
- Category
- Java
- Title
- java stream collect to string
- Category
- Java
- Title
- char array to arraylist java
- Category
- Java
- Title
- java print type of object
- Category
- Java
- Title
- jackson ignore values if empty
- Category
- Java
- Title
- how to replace all of one character with nothing in java
- Category
- Java
- Title
- string contains java
- Category
- Java
- Title
- java hello world
- Category
- Java
- Title
- editer un label java
- Category
- Java
- Title
- tower of hanoi program in java using recursion
- Category
- Java
- Title
- declare int java
- Category
- Java
- Title
- java min function
- Category
- Java
- Title
- tableau de classe java
- Category
- Java
- Title
- continue in java
- Category
- Java
- Title
- check if map contains key java
- Category
- Java
- Title
- how to copy list item to another list in java
- Category
- Java
- Title
- how to remove a certain string in a arraylist java
- Category
- Java
- Title
- java create directory
- Category
- Java
- Title
- java load image
- Category
- Java
- Title
- java array check duplicates
- Category
- Java
- Title
- double to string java
- Category
- Java
- Title
- Building a maven EAR project and specifying the configuration of which projects to include, what is the element in the plugin configuration that contains Enterprise Java Bean Projects:
- Category
- Java
- Title
- how to break two loop in java
- Category
- Java
- Title
- JOptionPane with drop down list java
- Category
- Java
- Title
- random code
- Category
- Java
- Title
- how to access private vairable in java method
- Category
- Java
- Title
- Spring Security JWT Authentication + PostgreSQL – RestAPIs SpringBoot + Spring MVC + Spring JPA
- Category
- Java
- Title
- java program to find prime number between 1 and 100
- Category
- Java
- Title
- spigot run command as console
- Category
- Java
- Title
- java switch display panel
- Category
- Java
- Title
- java insertion sort
- Category
- Java
- Title
- java sort array descending
- Category
- Java
- Title
- run spring boot application command line
- Category
- Java
- Title
- file to image javafx
- Category
- Java
- Title
- applicationcontext.xml
- Category
- Java
- Title
- queue implementation in java using arraylist
- Category
- Java
- Title
- list in java
- Category
- Java
- Title
- java int stream min
- Category
- Java
- Title
- Java If statemtn
- Category
- Java
- Title
- how to change maven java version in po,
- Category
- Java
- Title
- fragment manager in android
- Category
- Java