From 0d9f4f8189cf04378f2485d0b5f222a77f2dbb18 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Mon, 29 Apr 2024 03:11:56 +0000 Subject: Sun, Apr 28, 2024, 8:11 PM -07:00 --- wk5/pset/speller/dictionary.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'wk5') 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) { -- cgit v1.2.3