Empresa engajada
Implement a function all_anagram_groups() that, given many input strings, will identify and group words that are anagrams of each other. An anagram is word that is just a re-arrangement of the characters of another word, like "reap" and "pear" and "a per" (whitespace is ignored). But "pear" and "rep" are not, since "rep" does not have an "a". Also, "the" and "thee" are not anagrams, because "the" only has one "e". Given this example input: [ "pear","dirty room","amleth","reap","tinsel","hamlet","dormitory","listen","silent" ] The output should be an array-of-arrays (or list-of-lists) [ ["pear","reap"], ["dirty room","dormitory"], ["amleth","hamlet"], ["tinsel","listen","silent"] ]
Sigiloso
public void sort(String[] array) { Hashtable> hash = new Hashtable>(); /* Group words by anagram */ for (String s : array) { String key = sortchars(s); if (!hash.containsKey(key)) hash.put(key, new LinkedList()); LinkedList anagrams = hash.get(key); anagrams.push(s); } /* Convert hash table to array */ int index = 0; for (String key : hash.keySetQ) { LinkedList list = hash.get(key); for (String t : list) { array[index] = t; index++; } } }