Advertisement
Broatlas

trie_insert

Apr 23rd, 2016
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. int trie_insert   ( trie_node_t ** rootRef, char word[ ] ){
  2.         int i=0, index=0;
  3.         int len;
  4.         trie_node_t *tmp = *rootRef;
  5.     len = strlen(word);
  6.         for(i = 0;i<len;i++){
  7.             word[i] = tolower(word[i]);
  8.         }
  9.  
  10.     if (tmp == NULL) return EXIT_FAILURE;
  11.     for (i=0;i<len;i++) {
  12.             if (word[i] == '\0') index = 26;
  13.             else if (word[i] >= 'a' || word[i] <= 'z') {
  14.                 index = charToInt(tolower(word[i]));
  15.             }
  16.             else return EXIT_FAILURE;
  17.  
  18.             if (!tmp->child[index]) tmp->child[index] = trie_new();
  19.  
  20.             tmp = tmp->child[index];
  21.     }
  22.     tmp->end= '\0';
  23.  
  24.     return 1;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement