Bucket Sort in Java.

import java.util.*;
class Bucket{
public static void sort(int[] a, int maxVal) {
int [] bucket=new int[maxVal+1];
for (int i=0; i<bucket.length; i++) {
bucket[i]=0;
}
for (int i=0; i<a.length; i++) {
bucket[a[i]]++;
}
int outPos=0;
for (int i=0; i<bucket.length; i++) {
for (int j=0; j<bucket[i]; j++) {
a[outPos++]=i;
}
}
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("Enter the Max Value");
int maxVal=in.nextInt();
System.out.println("Enter the no. of elements");
//int u=in.nextInt();
int [] data=new int[in.nextInt()] ;
for(int i=0;i<data.length;i++)data[i]=in.nextInt();
sort(data,maxVal);
System.out.println(Arrays.toString(data));
}
}
posted by lol ik.
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteJava Training in Chennai Core Java Training in Chennai Core Java Training in Chennai
Java Online Training Java Training in Chennai
This comment has been removed by the author.
ReplyDeleteHi, today I decided to find some kind of part-time job on the Internet at home and found this site slapping live slots online at first I was afraid I was afraid that they would be deceived but I certainly took a chance and did not regret it, now I want to share with you
ReplyDelete