本文整理汇总了C++中TrieNode::findChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TrieNode::findChild方法的具体用法?C++ TrieNode::findChild怎么用?C++ TrieNode::findChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrieNode
的用法示例。
在下文中一共展示了TrieNode::findChild方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertWord
void Trie::insertWord(string word){
incrementWordCount();
TrieNode* node = root;
for(unsigned int i = 0; i < word.length(); i++){
if(node->findChild(word[i]) == NULL){
node = node->insertChild(word[i]);
}
else{
node = node->findChild(word[i]);
}
}
node->setIsWord();
node->instantiatePostingList(word); // implemented in trieNode
node->setDocFreq();
}
示例2: findWord
TrieNode* Trie::findWord(string word){
TrieNode* node = root;
for(unsigned int i = 0; i < word.length(); i++){
if(node->findChild(word[i]) == NULL){
return NULL;
}
else{
node = node->findChild(word[i]);
}
if(i == word.length()-1){
if(node->getIsWord() == true){
return node;
}
else{
return NULL;
}
}
}
}
示例3: searchWord
bool Trie::searchWord(string s) {
TrieNode* curr = root;
while(curr != NULL) {
for(int i = 0; i < s.length(); i++) {
TrieNode* tmp = curr->findChild(s[i]);
if(tmp == NULL)
return false;
curr = tmp;
}
if(curr->getWordMarker())
return true;
else
return false;
}
return false;
}
示例4: addWord
// Adds a word into the data structure.
void addWord(string word) {
TrieNode* current = root;
if (word.size() == 0) {
root->marker = true;
return;
}
for (int i = 0; i < word.size(); ++i) {
TrieNode* newnode = current->findChild(word[i]);
if (!newnode) {
newnode = new TrieNode(word[i]);
current->children.push_back(newnode);
}
current = newnode;
if (i == word.size() - 1) {
current->marker = true;
}
}
}
示例5: addWord
void Trie::addWord(string s) {
TrieNode* curr = root;
if(s.length() == 0) {
curr->setWordMarker();
return;
}
for(int i = 0; i < s.length(); i++) {
TrieNode* child = curr->findChild(s[i]);
if(child != NULL) {
curr = child;
} else {
TrieNode* tmp = new TrieNode();
tmp->setContent(s[i]);
curr->appendChild(tmp);
curr = tmp;
}
if(i == s.length() - 1)
curr->setWordMarker();
}
}