Java Bucket Sort on Strings
- by Michael
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.