Last active
August 29, 2015 14:00
-
-
Save jitsceait/06f478349d8e60b7e1d3 to your computer and use it in GitHub Desktop.
Trie search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int search(trie *t, char key[]){ | |
| int len = strlen(key); | |
| int i; | |
| if(t->root == NULL){ | |
| printf("\n Trie is not initialized\n"); | |
| } | |
| Node * current = t->root; | |
| for(i=0; i<len; i++){ | |
| int index = GET_CHAR_INDEX(key[i]); | |
| /* If characters are left in key and we have reached at | |
| NULL, there is no key present */ | |
| if(current->children[index] == NULL) return false; | |
| /* Else traverse down the trie */ | |
| current = current->children[index]; | |
| } | |
| /* If we have reached the lead=f node, key is present */ | |
| if(current && current->value == LEAF_NODE ) | |
| return true; | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment