Esempio n. 1
0
	// Returns if there is any word in the trie
	// that starts with the given prefix.
	bool startsWith(string prefix) {
		int len = prefix.length();
		if (len < 1)return false;
		TrieNode* ref = root;
		for (int i = 0; i < len; i++) {
			if (!ref || !ref->getDataPtr(prefix[i]))
				return false;
			ref = ref->getDataPtr(prefix[i]);
		}
		return true;
	}
Esempio n. 2
0
	// Returns if the word is in the trie.
	bool search(string word) {
		//if (!word) return false;
		int len = word.length();
		if (len < 1) return false;
		TrieNode* ref = root;
		for (int i = 0; i < len; i++) {
			if (!ref||!ref->getDataPtr(word[i]))
				return false;
			ref = ref->getDataPtr(word[i]);
		}
		return ref->isWord();
	}