Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. typedef struct TrieNode
  2. {
  3.     // number of times this string occurs in the corpus
  4.     int count;
  5.  
  6.     // 26 TrieNode pointers, one for each letter of the alphabet
  7.     struct TrieNode *children[26];
  8.  
  9.     // the co-occurrence subtrie for this string
  10.     struct TrieNode *subtrie;
  11. } TrieNode;
  12.  
  13. TrieNode *createTrieNode(void)
  14. {
  15.     int i;
  16.     TrieNode *node = NULL;
  17.     node = malloc(sizeof(TrieNode));
  18.     node->count = 0;
  19.     for (i = 0; i <26; i++)
  20.     {
  21.         node->children[i] = NULL;
  22.     }
  23.     node->subtrie = NULL;
  24.  
  25.     return node;
  26. }
  27.  
  28. TrieNode *insertString(TrieNode *root, char *str)
  29. {
  30.     if(*str == '\0')
  31.         return root;
  32.     TrieNode *temp = NULL;
  33.     if(root->children[*str - 97] == NULL)
  34.     {
  35.         temp = createTrieNode();
  36.         root->children[*str - 97] = temp;
  37.     }
  38.     //printf("%c\t%d\n", *str, *str - 97);
  39.     insertString(root->children[*str - 97], str + 1);
  40.     return root;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement