Trying to learn about tries in C-programming, and hope someone can help me understand how to parse the progression to subsequent levels of the ‘tree’ portion of the trie.
I’m trying to write an unload() function for a trie-based dictionary, and am providing what I think are the appropriate sections of code with which I'm working:
Structure declarations:
Code:
#define ALPHABET_SIZE (27)
#define LENGTH 7
#define CHAR_TO_INDEX(c) (tolower((int)c) - (int)'a')
char* word;
// trie node
typedef struct trie_node trie_node_t;
struct trie_node
{
int value;
trie_node_t *children[ALPHABET_SIZE];
};
// trie ADT
typedef struct trie trie_t;
struct trie
{
trie_node_t *root;
int count;
};
Function call:
Function I’ve written (so far), which reaches first ‘children’ level
Code:
void unload(trie_t *pTrie)
{
trie_node_t *pUnload;
pUnload = pTrie->root;
//make sure trie is present
if(pUnload !=NULL)
{
int alpharray;
for(alpharray = 0; alpharray<ALPHABET_SIZE ; alpharray++)
{
//this refers to first level array of trie
if( pUnload->children[k]!=NULL )
Question is "How do I parse pointers to the subsequent levels of "children": eg., where pTrie->count =2, 3, 4, etc.?
Thanks for any help.
Richard