Advertisement
Jodyone

check.c

Oct 23rd, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. bool check(const char* word)
  2. {
  3.     // TODO
  4.     char new_word[LENGTH + 1];
  5.     for (int i = 0, n = strlen(word); i <= n; i++)
  6.     {
  7.         new_word[i] = word[i];
  8.         new_word[i] = tolower(new_word[i]);
  9.     }
  10.      
  11.     // determine the correct hash position
  12.     int y = hash_d(new_word);
  13.  
  14.     // point the cursor to the first item in the list we identified
  15.     node* cursor = hashtable[y];
  16.     node* prev = NULL;
  17.     // search the linked list
  18.     while (cursor != NULL)
  19.     {
  20.         if (strcmp(cursor->word,new_word) == 0)
  21.         {
  22.            // if (word isn't top of list)
  23.             if (prev != NULL)
  24.             {
  25.                     // move word to top of list        
  26.                 prev->next = cursor->next;              
  27.                     cursor->next = hashtable[y];
  28.                     hashtable[y] = cursor;
  29.                
  30.             }
  31.              return true;
  32.            
  33.         }
  34.         else
  35.         {
  36.                 // previous = cursor
  37.             prev = cursor;
  38.                 cursor = cursor->next;
  39.         }
  40.     }
  41.     return false;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement