I am trying to create a Trie
Implementation in C++. I cannot figure out how to print all words stored in the Trie
.
This is how I've implemented the TrieNode
.
struct TrieNode{
bool isWord;
int data; //Number of times Word Occured
TrieNode *Child[ALPHABET_SIZE]; //defined as 26
};
I know I could store a pointer
to the parent node, Depth-First Search for all nodes where isWord==True
and recursively print each word from those nodes.
But I'm wondering is there a way to print out each word in the Trie
with my implementation of a TrieNode
.
Thanks for any help.
data
? I understandisWord
and theChild
array (why notchildren
?) gives the children... but what doesdata
stand for ? – Lifeguard