All words in a trie data-structure
Posted
by
John Smith
on Stack Overflow
See other posts from Stack Overflow
or by John Smith
Published on 2012-10-20T16:57:31Z
Indexed on
2012/10/20
17:00 UTC
Read the original article
Hit count: 325
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?
© Stack Overflow or respective owner