Currently, I'm simply inserting the word into the dictionary (ArrayList<String>
) and then sorting the dictionary like so:
dictionary.add(newWord);
Collections.sort(dictionary, new Comparator<String>(){
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
I'm trying to determine whether this way is really the best. The other way, of course, is to find the correct point in the dictionary and then insert the word there. The problem is, I haven't been able to come up with an efficient/reliable way to find that point within the dictionary. I've got a few ideas flying around in my head but it's really tricky putting pen to paper.
If you have an idea of how to do it, please don't post any massive code answers. This is part of an assignment, so instead of posting code could you walk me through how you'd do it? (maybe in pseudocode?)
Thank you.