Beispiel #1
0
static void wordDictionaryFree(WordDictionary* obj)
{
    int i;
    for (i = 0; i < sizeof(obj->letters); i++) {
        if (obj->subs[i] != NULL) {
            wordDictionaryFree(obj->subs[i]);
        }
    }
    free(obj);
}
/** Deallocates memory previously allocated for the data structure. */
void wordDictionaryFree(struct WordDictionary* wordDictionary) {
    struct WordDictionary *temp;
    int i;
    temp=wordDictionary;
    if(temp!=NULL){
        for(i=0;i<26;i++){
            if(temp->next[i]!=NULL) wordDictionaryFree(temp->next[i]);
        }
        free(temp);
    }
}
Beispiel #3
0
int main(void)
{
    char *word1 = "abc";
    char *word2 = "ab";
    char *word3 = "...";

    WordDictionary* obj = wordDictionaryCreate();
    wordDictionaryInsert(obj, word1);
    printf("%s\n", wordDictionarySearch(obj, word1) ? "true" : "false");
    printf("%s\n", wordDictionarySearch(obj, word2) ? "true" : "false");
    wordDictionaryInsert(obj, word2);
    printf("%s\n", wordDictionarySearch(obj, word2) ? "true" : "false");
    wordDictionaryInsert(obj, word2);
    printf("%s\n", wordDictionarySearch(obj, word3) ? "true" : "false");
    wordDictionaryFree(obj);
    return 0;
}