Skip to content

Imbilu/Trie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This code is a C program that implements a trie data structure to store and search for popular dog names. A trie is a tree-like data structure that can store words in an efficient way. Each node in the trie has an array of pointers to its children nodes, one for each letter of the alphabet. Each node also has a boolean value that indicates whether it is the end of a word or not.

The code has four main functions:

  • main:

  • This function takes a command line argument that specifies the name of a file that contains a list of popular dog names.

    • It opens the file and reads each name into a buffer. It then calls the check function to see if the name is already in the trie.
    • If not, it adds the name to the trie by creating new nodes as needed. It then prompts the user to enter a word and calls the check function again to see if the word is a popular dog name or not.
    • It prints the result and then calls the unload function to free the memory allocated for the trie.
  • check: This function takes a word as a parameter and returns a boolean value that indicates whether the word is a popular dog name or not.

    • It traverses the trie from the root node, following the pointers that correspond to each letter of the word. If it reaches a node that is the end of a word, it returns true.
    • If it reaches a node that is null or has no children, it returns false. It also handles invalid input by returning false for words that contain non-alphabetic characters or are out of bounds.
  • unload: This function frees the memory allocated for the trie. It calls a recursive helper function called unloader that takes a node as a parameter and frees all its children nodes before freeing itself.

  • It then returns true if the operation is successful.

  • unloader: This is a recursive helper function that takes a node as a parameter and frees all its children nodes before freeing itself.

  • It loops through the array of pointers of the node and calls itself on each non-null child node. It then frees the node and returns to the previous call.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages