i think u can try the following approach, store the words into a vector,
(or a trie, if program efficienty is impt). and the just use the same method
the merge step from merge sort.
In fact, i doubt if your approach is really work. For exmaple:
if u meet two word shioth, and shiito, will u filter them or not? they are
'legal' words from dictionary.