I am working on a dictionary using a trie with the following struct in c
struct trie_node {
int is_end; //0 is is not the end of the word ,otherwise 1
char c;
struct trie_node* child[26];
};
I am able to insert words, search words and I would like to print all the words of the dictionary. Not sure how to handle it. I was trying to print
void print(struct trie_node node) {
int i = 0;
for (i = 0; i < 26; i++) {
if (node->child[i] != NULL) {
printf("%c", node->child[i]->c);
print(node->child[i]);
}
}
}
But it is not printing correctly if for example I have the words beer bee bear beast
it is printing bearster it should print bearbeastbeebeer
How can I print correctly the list of words ?