Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. bool check(const char *word)
  2. {
  3. // index number for node children 0 to 26
  4. int x = 0;
  5.  
  6. // Index for letters in 'word'
  7. int i = 0;
  8.  
  9. // Traverse pointer, starting at root
  10. for(node *ptr = root; word[i] != 0; ptr = ptr->children[x])
  11. {
  12. // converts letter to index
  13. if (word[i] == '\'')
  14. {
  15. x = 26;
  16. }
  17. else
  18. {
  19. x = word[i] - 'a';
  20. }
  21.  
  22. // Well, if the current letter in question doesnt have a pointer in the currnt node then the word is misspelled
  23. if (ptr->children[x] == NULL)
  24. {
  25. return false;
  26. }
  27.  
  28. if (word[i + 1] == 0)
  29. {
  30. if (ptr->is_word == false)
  31. {
  32. return false;
  33. }
  34. else
  35. {
  36. return true;
  37. }
  38. }
  39.  
  40. i++;
  41. }
  42. return false;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement