Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool check(const char* word)
- {
- // TODO
- char new_word[LENGTH + 1];
- for (int i = 0, n = strlen(word); i <= n; i++)
- {
- new_word[i] = word[i];
- new_word[i] = tolower(new_word[i]);
- }
- // determine the correct hash position
- int y = hash_d(new_word);
- // point the cursor to the first item in the list we identified
- node* cursor = hashtable[y];
- node* prev = NULL;
- // search the linked list
- while (cursor != NULL)
- {
- if (strcmp(cursor->word,new_word) == 0)
- {
- // if (word isn't top of list)
- if (prev != NULL)
- {
- // move word to top of list
- prev->next = cursor->next;
- cursor->next = hashtable[y];
- hashtable[y] = cursor;
- }
- return true;
- }
- else
- {
- // previous = cursor
- prev = cursor;
- cursor = cursor->next;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement