Complete the code to check if the current node marks the end of a word.
if node.is_end_of_word [1] { return true; }
The search should return true if the node's is_end_of_word flag is true, indicating a complete word.
Complete the code to get the index of the child node for the current character.
let index = (word.chars().nth(i).unwrap() as usize) [1] ('a' as usize);
To find the child index for a character, subtract the ASCII value of 'a' from the character's ASCII value.
Fix the error in the code to check if the child node exists before continuing the search.
if node.children[index] [1] None { return false; }
We must check if the child node is None to know if the path exists. Using '==' compares correctly.
Fill both blanks to correctly move to the child node and continue the search.
node = node.children[[1]].as_ref().unwrap(); i += [2];
We use the calculated index to access the child node and increment i by 1 to move to the next character.
Fill all three blanks to complete the search function that returns true if the word exists in the trie.
fn search(&self, word: &str) -> bool {
let mut node = &self.root;
let mut i = 0;
while i < word.len() {
let index = (word.chars().nth(i).unwrap() as usize) [1] ('a' as usize);
if node.children[index] [2] None {
return false;
}
node = node.children[index].as_ref().unwrap();
i [3];
}
node.is_end_of_word == true
}The search subtracts 'a' from the character to get the index, checks if the child is None using '==', and increments i by 1 to move forward.
