All words in a trie data-structure
- by John Smith
I'm trying to put all words in a trie in a string, a word is detonated by the eow field being true for a certain character in the trie data structure, hence a trie can could have letters than lead up to no word, for ex "abc" is in the trie but "c"'s eow field is false so "abc" is not a word
Here is my Data structure
struct Trie {
bool eow; //when a Trie field isWord = true, hence there is a word
char letter;
Trie *letters[27];
};
and here is my attemped print-all function, basically trying to return all words in one string seperated by spaces for words
string printAll( string word, Trie& data)
{
if (data.eow == 1)
return word + " ";
for (int i = 0; i < 26; i++) {
if (data.letters[i] != NULL)
printAll( word + data.letters[i]->letter, *(data.letters[i]));
}
return "";
}
Its not outputting what i want, any suggestions?