Java Bucket Sort on Strings
Posted
by Michael
on Stack Overflow
See other posts from Stack Overflow
or by Michael
Published on 2010-03-31T00:55:38Z
Indexed on
2010/03/31
1:03 UTC
Read the original article
Hit count: 349
I can't figure out what would be the best way to use Bucket Sort to sort a list of strings that will always be the same length.
An algorithm would look like this:
For the last character position down to the first:
For each word in the list:
Place the word into the appropriate bucket by current character
For each of the 26 buckets(arraylists)
Copy every word back to the list
I'm writing in java and I'm using an arraylist for the main list that stores the unsorted strings. The strings will be five characters long each.
This is what I started. It just abrubdly stops within the second for loop because I don't know what to do next or if I did the first part right.
ArrayList<String> count = new ArrayList<String>(26);
for (int i = wordlen; i > 0; i--) {
for (int j = 0; i < myList.size(); i++)
myList.get(j).charAt(i)
}
Thanks in advanced.
© Stack Overflow or respective owner