summaryrefslogtreecommitdiff
path: root/wk5/pset/speller/dictionary.c
diff options
context:
space:
mode:
authorFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-04-29 03:11:56 +0000
committerFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-04-29 03:11:56 +0000
commit0d9f4f8189cf04378f2485d0b5f222a77f2dbb18 (patch)
tree43e6d0dec61a16be1bcc38a7dc53838213483b93 /wk5/pset/speller/dictionary.c
parent3711956db6619b32edb626d25ddea4e324c6a040 (diff)
Sun, Apr 28, 2024, 8:11 PM -07:00
Diffstat (limited to 'wk5/pset/speller/dictionary.c')
-rw-r--r--wk5/pset/speller/dictionary.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/wk5/pset/speller/dictionary.c b/wk5/pset/speller/dictionary.c
index cf2d6d1..c095ad4 100644
--- a/wk5/pset/speller/dictionary.c
+++ b/wk5/pset/speller/dictionary.c
@@ -26,10 +26,25 @@ int siz = 0;
// Returns true if word is in dictionary, else false
bool check(const char *word)
{
- // TODO
+ // hash word to find bucket
+ int val = hash(word);
+ node *current = table[val];
+
+ // check all nodes in the bucket
+ while (current != NULL)
+ {
+ // check if this is the word
+ if (strcmp(current->word, word) == 0)
+ {
+ return true;
+ }
+ current = current->next;
+ }
+
return false;
}
+
// Hashes word to a number
unsigned int hash(const char *word)
{