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 3 of 3

Thread: Bucket Sort Help

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

    Default Bucket Sort Help

    So, this is what I've got down so far with my BucketSort.java I created two buckets, master bucket and sub buckets[10].

    • Ask user to enter integers from 0 - 9999
    • Take user input and add to master bucket
    • Now use BucketSort method to take from master bucket and sort into sub buckets
    • Then use other method to take elements in sub bucket starting from bucket[9] and return to mast bucket


    I got the sorting method down, and understand what is happening. But now what puzzles me is what happens if the user inputs different sizes? For example they input [1234, 123, 12, 1]. My sorting method would only sort either size 4, size 3, size 2, or size 1 but not all simultaneously. Is there a way to create a method that will help you sort all sizes? Mine is only formatted for the user to only enter sizes 4.

    public static void MtoS(int p)//user inputs 3, 2, 1, 0 for p
    {
    while(!(mBucket.isEmpty()))
    	{
     
            String a = (String)mBucket.remove(0);//remove element(0)	
    	char c = a.charAt(p);//element(0) at position p
    	int k = (int)c - (int)'0';//use to convert char to int		
     
    		for(int n = 0; n < 10; n++)
    		{
     
    			if(k == n)//if element(0) at charAt(3) equals to n
    			{
     
    				sBucket[n].add(a);//keep looping till p == n, then adds to corresponding sBucket
     
    			}
    		}
    		}


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Bucket Sort Help

    This thread has been cross posted here:

    Bucket or Bin Sort

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


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

    Default Re: Bucket Sort Help

    it wasn't cross posted if you read my last post. My last post stated i didn't know how to create the algorithm. Now i created the algorithm but now I need help finding a way to sort multiple sizes.

Similar Threads

  1. [SOLVED] Bucket or Bin Sort
    By itispj in forum Java Theory & Questions
    Replies: 1
    Last Post: October 15th, 2011, 07:14 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, 10:44 AM