Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool check(const char *word)
- {
- // index number for node children 0 to 26
- int x = 0;
- // Index for letters in 'word'
- int i = 0;
- // Traverse pointer, starting at root
- for(node *ptr = root; word[i] != 0; ptr = ptr->children[x])
- {
- // converts letter to index
- if (word[i] == '\'')
- {
- x = 26;
- }
- else
- {
- x = word[i] - 'a';
- }
- // Well, if the current letter in question doesnt have a pointer in the currnt node then the word is misspelled
- if (ptr->children[x] == NULL)
- {
- return false;
- }
- if (word[i + 1] == 0)
- {
- if (ptr->is_word == false)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- i++;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement