Example #1
0
int Trie::search(char word[]) {
	int len = strlen(word);
	TNode* current = root;
	int i = 0;
	while (current != NULL && i < len)
		current = current->exist_child(tolower(word[i++]));
	
	return (current != NULL && current->end_of_word());
}
Example #2
0
int Trie::insert(char word[]) {
	int len = strlen(word);
	TNode* current = root;
	int i = 0; char c;
	// processing each character
	while (i < len) {
		c = word[i++];
		if (current->exist_child(c) == NULL)
			num_nodes++;
		current = current->get_child_node(tolower(c));
	}
	if (!current->end_of_word()) {
		num_words++;
		current->set_end_of_word(true);
	}
}