当前位置: 首页>>代码示例>>C++>>正文


C++ TrieNode::FindChild方法代码示例

本文整理汇总了C++中TrieNode::FindChild方法的典型用法代码示例。如果您正苦于以下问题:C++ TrieNode::FindChild方法的具体用法?C++ TrieNode::FindChild怎么用?C++ TrieNode::FindChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TrieNode的用法示例。


在下文中一共展示了TrieNode::FindChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AddWord

void Trie::AddWord(string s) {
    TrieNode* current = root;
    
    
    if(s.length() == 0)
    {
        current->Mark(); // recognize empty word
        return;
    }
    
    unsigned long len = s.length();
    for (int i=0; i<len-1; i++) {
        
        TrieNode *child = current->FindChild(s[i]);
        
        if(child != NULL)
        {
            current = child;
        }
        else {
            TrieNode* tmp = new TrieNode(s[i], false);
            tmp->Set(s[i]);
            current->AddChild(tmp);
            current = tmp;
        }
        
        if (s[i+1]=='/') {
            current->Mark();
            break;
        }
        
        if ( i == len - 2 )
            current->Mark();
    }
}
开发者ID:gk95,项目名称:Wordz-Solver,代码行数:35,代码来源:Trie.cpp

示例2: SearchWord

bool Trie::SearchWord(string s) {
    TrieNode* current = root;
    unsigned long len = s.length();
    
    for (int i=0; i<len; i++) {
        current = current->FindChild(s[i]);
        
        if(current == NULL)
            return false;
    }
    
    if(current->IsFinal())
        return true;
    
    return false;
}
开发者ID:gk95,项目名称:Wordz-Solver,代码行数:16,代码来源:Trie.cpp

示例3: insert

 // Inserts a word into the trie.
 void insert(string s) 
 {
     TrieNode *prev = nullptr;
     TrieNode *curr = m_root;
     // We check the characters of s one by one. Note that 
     // we also add the NULL terminator to the Trie which 
     // indicates the end of a word.
     for (int i = 0; i <= s.length(); i++)
     {
         prev = curr;
         curr = prev->FindChild(s[i]);
         
         // Can't find a TrieNode with the character s[i], 
         // so create a new one and add it to the children 
         // list of prev.
         if (curr == nullptr)
         {
             curr = new TrieNode(s[i]);
             prev->AddChild(curr);
         }
     }
 }
开发者ID:renweizhukov,项目名称:CodeLiteProjects,代码行数:23,代码来源:main.cpp

示例4: findWordsStartFromOneCell

 void findWordsStartFromOneCell(
     vector<vector<char>>& board,
     int m,
     int n,
     int i,
     int j,
     TrieNode* currNode,
     string& word,
     vector<string>& foundWords)
 {
     TrieNode *childNode = currNode->FindChild(board[i][j]);
     if (childNode == nullptr)
     {
         return;
     }
     
     word.push_back(board[i][j]);
     board[i][j] = 'X';
     TrieNode *wordEndNode = childNode->FindChild(0);
     if ((wordEndNode != nullptr) && (wordEndNode->GetChar() != 'X'))
     {
         foundWords.push_back(word);
         wordEndNode->SetChar('X');
     }
     
     if ((i > 0) && (board[i - 1][j] != 'X'))
     {
         findWordsStartFromOneCell(
             board,
             m,
             n,
             i - 1,
             j,
             childNode,
             word,
             foundWords);
     }
     
     if ((i < m - 1) && (board[i + 1][j] != 'X'))
     {
         findWordsStartFromOneCell(
             board,
             m,
             n,
             i + 1,
             j,
             childNode,
             word,
             foundWords);
     }
     
     if ((j > 0) && (board[i][j - 1] != 'X'))
     {
         findWordsStartFromOneCell(
             board,
             m,
             n,
             i,
             j - 1,
             childNode,
             word,
             foundWords);            
     }
     
     if ((j < n - 1) && (board[i][j + 1] != 'X'))
     {
         findWordsStartFromOneCell(
             board,
             m,
             n,
             i,
             j + 1,
             childNode,
             word,
             foundWords);    
     }
     
     board[i][j] = word.back();
     word.pop_back();
 }
开发者ID:renweizhukov,项目名称:CodeLiteProjects,代码行数:80,代码来源:main.cpp


注:本文中的TrieNode::FindChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。