Guest User

Untitled

a guest
Jun 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. int[] num = { 3,6,1,7,2,8,10,4,9,5};
  4. int n = num.length;
  5.  
  6. bucketSort(num);
  7.  
  8. for (int h = 0; h < n; h++)
  9. System.out.print(num[h]+ " ");
  10. }
  11.  
  12.  
  13. public static int[] bucketSort(int[] arr) {
  14. int i, j;
  15. int[] bucket = new int[arr.length+1];
  16. Arrays.fill(bucket, 0);
  17.  
  18. for (i = 0; i < arr.length; i++) {
  19. bucket[arr[i]]++;
  20. }
  21.  
  22. int k=0;
  23. for (i = 0; i < bucket.length; i++) {
  24. for (j = 0; j<bucket[i]; j++) {
  25. arr[k++] = i;
  26. }
  27. }
  28. return arr;
  29. }
Add Comment
Please, Sign In to add comment