本文整理汇总了C++中TrieNode::addNode方法的典型用法代码示例。如果您正苦于以下问题:C++ TrieNode::addNode方法的具体用法?C++ TrieNode::addNode怎么用?C++ TrieNode::addNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrieNode
的用法示例。
在下文中一共展示了TrieNode::addNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addWord
void Dictionary::addWord( const std::string &word )
{
TrieNode *node = root_;
int tmp = 0;
for ( auto it = word.rbegin(); it != word.rend(); ++it )
{
char c = *it;
if ( !isdigit(c) && !isalpha(c) )
{
++tmp;
continue;
}
TrieNode *next_node = node->contain(c);
if ( next_node )
{
node = next_node;
continue;
}
node = node->addNode(c);
}
max_length_ = std::max( max_length_, word.size() - tmp );
if ( node != root_ )
{
node->setEndWord(true);
}
}
示例2: insert
void Trie::insert(const std::string& stringToInsert)
{
TrieNode* currentNode = this->root.get();
for(auto stringIt = stringToInsert.begin(); stringIt != stringToInsert.end(); ++stringIt)
{
char currentChar = *stringIt;
bool done = false;
// 2. if there is a node with value == c, set that node as current node. Repeat.
for (auto it = currentNode->children.begin(); it != currentNode->children.end() && !done; ++it)
{
if ((*it)->value == currentChar)
{
currentNode = *it;
done = true;
}
}
if(done)
continue;
// 3. if not, insert a node and go to 2.
currentNode = currentNode->addNode(currentChar);
}
currentNode->hasString = true;
}
示例3: insert
// Inserts a word into the trie.
void insert(string word) {
TrieNode* itr = root;
for (int i = 0; i < word.length(); ++i) {
itr = itr->addNode(word[i]);
}
if (itr != root) {
itr->setWordEnd();
}
}