Import Java. util. arraylist; import Java. util. iterator;/*** bucket sorting: the idea of Bucket sorting is to divide the interval [0, 1) into N subintervals of the same size. This is called a bucket, then, N inputs are distributed to each bucket. * Because the input numbers are evenly distributed independently in [), there is usually no large number in a bucket. * To get the result, sort the number in each bucket first, and then list the elements in each bucket in order. * The time complexity of Bucket sorting is O (n) */public class bucketsort {/***. Algorithm To sort buckets in arr. The sorting result is still in arr * @ Param arr */static void bucketsort (double arr []) {int n = arr. length; arraylist arrlist [] = new arraylist [N]; // evenly distributes the numbers in arr to [0, 1). Each bucket is a list, the element for (INT I = 0; I <n; I ++) {int temp = (INT) math. floor (N * arr [I]); If (null = arrlist [temp]) arrlist [temp] = new arraylist (); arrlist [temp]. add (ARR [I]) ;}// sort the numbers in each bucket by insert (INT I = 0; I <n; I ++) {If (null! = Arrlist [I]) insert (arrlist [I]);} // merge the sorting results of each bucket into int COUNT = 0; For (INT I = 0; I <N; I ++) {If (null! = Arrlist [I]) {iterator iter = arrlist [I]. iterator (); While (ITER. hasnext () {double D = (double) ITER. next (); arr [count] = D; count ++ ;}}}} /*** sort each bucket by insert. * @ Param list */static void insert (arraylist list) {If (list. size ()> 1) {for (INT I = 1; I <list. size (); I ++) {If (double) list. get (I) <(double) list. get (I-1) {double temp = (double) list. get (I); Int J = I-1; For (; j> = 0 & (double) list. get (j)> (double) list. get (J + 1); j --) list. set (J + 1, list. get (j); list. set (J + 1, temp) ;}}}/*** test ..... * The test data here is an array containing n elements, and each element must meet 0 <= arr [I] <1 */public static void main (string [] ARGs) {double arr [] = {0.78, 0.17, 0.39, 0.26, 0.72, 0.94, 0.21, 0.12, 0.23}; bucketsort (ARR); For (INT I = 0; I <arr. length; I ++) system. out. println (ARR [I]);}