本文整理汇总了C++中TrieNode::get方法的典型用法代码示例。如果您正苦于以下问题:C++ TrieNode::get方法的具体用法?C++ TrieNode::get怎么用?C++ TrieNode::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrieNode
的用法示例。
在下文中一共展示了TrieNode::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
TrieNode *searchPattern(string word) {
typedef std::pair<TrieNode *, int> Match;
stack<Match>s;
s.push(make_pair(root, 0));
int len = word.length();
while (!s.empty()) {
Match m = s.top();
TrieNode *node = m.first;
s.pop();
int id = m.second;
if (id >= len) {
if (node->isEnd() || s.empty()) {
return node;
}
continue;
}
char ch = word[m.second];
if (ch == '.') {
for (int i = 0; i < TrieNode::R; i++) {
if (node->links[i]) {
s.push(make_pair(node->links[i], id + 1));
}
}
} else if (node->containsKey(ch)) {
s.push(make_pair(node->get(ch), id + 1));
}
}
return NULL;
}
示例2: insert
// Inserts a word into the trie.
void insert(string word) {
TrieNode *node = root;
for (int i = 0; i < word.length(); i++) {
char currentChar = word[i];
if (!node->containsKey(currentChar)) {
node->put(currentChar, new TrieNode());
}
node = node->get(currentChar);
}
node->setEnd();
}
示例3:
// search a prefix or whole key in trie and
// returns the node where search ends
TrieNode *searchPrefix(string word) {
TrieNode *node = root;
for (int i = 0; i < word.length(); i++) {
char curLetter = word[i];
if (node->containsKey(curLetter)) {
node = node->get(curLetter);
} else {
return NULL;
}
}
return node;
}