struct Trie *insertInTrie(struct Trie **root, char *word) { if(!*word) return; if(!*root) { struct Trie *Node = (struct Trie *)malloc(sizeof(struct Trie)); Node->data = *word; int i; for(i=0; i<26;i++) Node->child[i] = NULL; if(!*(word+1)) Node->endof = 1; else{ Node->child[*word] = insertInTrie(&(Node->child[*word]), word+1); return Node; } }else {(*root)->child[*word] = insertInTrie(&(*root)->child[*word], word+1); return (*root); } }
int main() { struct Trie *root=NULL; char *word="abcd"; insertInTrie(&root, word); searchInTrie(root, word); }
ACListe preAC(char** mots, int nbrMots){ ACListe acListe = createACListe(); int i; for(i = 0; i < nbrMots; i++){ if(mots[i] == NULL){ break; } else{ insertInTrie(acListe->trie, mots[i]); } } completer(acListe); return acListe; }
bool load(const char *dictionary) { char *word = NULL; size_t len = 0; FILE *fp = fopen(dictionary, "r"); if (fp == NULL) return false; rootNode = getNode(); while (getline(&word, &len, fp) != -1) { if (word[strlen(word) - 1] == '\n') word[strlen(word) - 1] = '\0'; // remove new line character insertInTrie(word); } free(word); fclose(fp); return true; }
void entrer (char * w, AcTrie acTrie) { int e = insertInTrie (acTrie->trie, w); acTrie->sortie[e] = 1; }