So I have a question that's kinda weird.
I have a list of "Word" objects. A "Word" object contains one string, myCWord which is equal to the canonical version of a String passed into the Word.
For example:
Word one = new Word("cba");
one.getMyCWord(); // returns abc
Canonical form is the sorted characters in the String.
So now I have a list of words, where I can access the canonical version of the Strings they hold.
I need an algorithm to create "sub lists" which are lists of which contain a set of words which are anagrams of eachother.
So if I have:
List<AnagramSet> aSet = new LinkedList<AnagramSet>();
List<Word> words = new LinkedList<Word>();
words.add("ok"); // cword returns ko
words.add("abc"); // cword returns abc
words.add("cba"); // cword returns abc still
someMethod(words);
someMethod(List<Word> a) {
// build new sub lists
AnagramSet.add(new Anagram(temp));
}
How can I build the sublists correctly?