Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Bucket or Bin Sort

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation 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.


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bucket or Bin Sort

    i figured it out.

Similar Threads

  1. Bubble Sort help
    By baueml01 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 5th, 2011, 08:47 PM
  2. Arrays.Sort Help
    By Brandon Seale in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 20th, 2011, 02:32 AM
  3. Timing a sort
    By joshft91 in forum Collections and Generics
    Replies: 1
    Last Post: February 7th, 2011, 05:12 PM
  4. Insertion Sort
    By Kimimaru in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 6th, 2010, 06:26 AM
  5. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 09:44 AM

Tags for this Thread