-
Bucket or Bin Sort
I'm trying to figure out how to create a BucketSort program, but I keep running into speed bumps. So far... I've created two arrayList
public static ArrayList mBucket = new ArrayList();//master bucket
public static ArrayList sBucket[] = new ArrayList[10];//sort buckets
and used a for loop on sBucket to create buckets 0-9. I ask the user to input any integer from 0 - 9999 and from that, I take what the user inputs and add it to mBucket.
Now this is where I get stuck. I understand the concept of bucketSort and that it uses multiple buckets to sort. From that, you end up with a sorted mBucket. I have a visual of what I am suppose to do but it is a bunch of if statement and for loops. For example:
for(int a = 0; a <= mBucket.size(); a++)
{
n = (String) mBucket.remove(0);
if(n.charAt(n.length()-1) == 0)
{
sBucket[0].add(n);
}
}
and so on. The loops would just continue from 0 - 9, checking each individual char position ( .charAt(4) would be position 3 in my case which is the ones place). So... I'm just wondering if there is an easier way to figure this bucket sort thing out??? Some help please.
-
Re: Bucket or Bin Sort