Here is a java program to Sort an Integer array with Bucket Sort
Output of the Program :
Try By Yourself Here : http://ideone.com/OpHXmH
class BucketSort {
public int[] bucketSort(int[] array) {
// create an array the size of the largest value + 1
int[] bucket = new int[100];
// for every value in array, increment its corresponding bucket
for (int i = 0; i < array.length; i++)
bucket[array[i]]++;
int outPos = 0;
for (int i = 0; i < bucket.length; i++) {
if (bucket[i] > 0)
array[outPos++] = i;
}
return array;
}
public static void main(String args[]){
BucketSort bSort = new BucketSort();
int[] array = { 77, 99, 44, 55, 22, 88, 11, 0, 66, 33 };
int[] sortedArray = bSort.bucketSort(array);
for (int i = 0; i < array.length; i++)
System.out.println(sortedArray[i]);
}
}
Output of the Program :
0 11 22 33 44 55 66
Try By Yourself Here : http://ideone.com/OpHXmH