#ifndef __TRIE_H__ #define __TRIE_H__ /** * trie.h * A simple trie implementation, designed as a sample answer to * problem 2 on exam 2. */ // +-----------+----------------------------------------------------- // | Constants | // +-----------+ /** * The maximum number of characters in a string. */ #define MAXSTRING 31 // +-------+--------------------------------------------------------- // | Types | // +-------+ typedef struct TrieNode TrieNode; // +--------------------+-------------------------------------------- // | Exported Functions | // +--------------------+ /** * Allocate a new node. Returns NULL if out of memory or other * allocation problems. */ TrieNode *new_node (void); /** * Add a new string to the trie. Updates the trie. Returns 1 if * successful and 0 if not. * * @pre: str is not "" */ int trie_add (TrieNode *trie, char *str); /** * Remove a string from the trie. Updates the trie. Returns 1 if * successful and 0 if not. */ int trie_remove (TrieNode *trie, char *str); /** * Find all of the strings that start with a given prefix and print * them out. */ int trie_find (TrieNode *trie, char *prefix); /** * Free the space allocated to a trie. */ void triee_free (TrieNode *trie); #endif // __TRIE_H__