diff options
author | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-04-29 02:54:26 +0000 |
---|---|---|
committer | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-04-29 02:54:26 +0000 |
commit | 52f306460bf9e45bb8b4535a4bde824c0f4e5097 (patch) | |
tree | 02b1d80b1514938049e01e6110decc2ed85aaf73 /wk5/pset | |
parent | 5c5344da3f2af1f8379f19d8393674a3c47ab499 (diff) |
Sun, Apr 28, 2024, 7:54 PM -07:00
Diffstat (limited to 'wk5/pset')
-rw-r--r-- | wk5/pset/speller/dictionary.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/wk5/pset/speller/dictionary.c b/wk5/pset/speller/dictionary.c index 54b4b24..7e5cc61 100644 --- a/wk5/pset/speller/dictionary.c +++ b/wk5/pset/speller/dictionary.c @@ -96,11 +96,19 @@ bool load(const char *dictionary) // hash the word to find the bucket it goes in int val = hash(ptr->word); // put new node at begining of bucket - if (table[val] != NULL) + if (table[val] == NULL) { - ptr->next = table[val]; + // if empty put it there + table[val] = ptr; } + else + { + // if not empty move the current first one down, + // then put the new one there + ptr->next = table[val]; table[val] = ptr; + } + } // Close the dictionary file |