本文整理汇总了C++中TrieNode::find方法的典型用法代码示例。如果您正苦于以下问题:C++ TrieNode::find方法的具体用法?C++ TrieNode::find怎么用?C++ TrieNode::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrieNode
的用法示例。
在下文中一共展示了TrieNode::find方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: naiveTest
void naiveTest() {
TrieNode* trie = new TrieNode();
trie->insert("HELLO",1);
assert(1 == trie->find("HELLO")->terminal);
assert(NULL == trie->find("HELLOB"));
assert(-1 == trie->find("HELL")->terminal);
delete trie;
}
示例2: search
// Returns if the word is in the trie.
bool search(string word) {
TrieNode *cur = root, *tmp;
for (auto c: word) {
if ((tmp = cur->find(c)) == NULL)
return false;
cur = tmp;
}
return cur->find('\0') != NULL;
}
示例3: search
// Returns if the word is in the trie.
bool search(string word) {
TrieNode* node = root;
for(int i = 0; i < word.length(); i++)
{
TrieNode* nextNode = node->find(word[i]);
if(!nextNode)
return false;
node = nextNode;
}
TrieNode* finalNode = node->find('\0');
if(finalNode)
return true;
else
return false;
}
示例4: startsWith
// Returns if there is any word in the trie
// that starts with the given prefix.
bool startsWith(string prefix) {
TrieNode *cur = root, *tmp;
for (auto c: prefix) {
if ((tmp = cur->find(c)) == NULL)
return false;
cur = tmp;
}
return true;
}
示例5: insert
// Inserts a word into the trie.
void insert(string word) {
TrieNode *cur = root, *tmp;
for (auto c: word) {
if ((tmp = cur->find(c)) == NULL) {
tmp = cur->insert(c);
}
cur = tmp;
}
cur->insert('\0');
}
示例6: startsWith
// Returns if there is any word in the trie
// that starts with the given prefix.
bool startsWith(string prefix) {
TrieNode* node = root;
for(int i = 0; i < prefix.length(); i++)
{
TrieNode* nextNode = node->find(prefix[i]);
if(!nextNode)
return false;
node = nextNode;
}
return true;
}
示例7: main
int main() {
TrieNode* ptn = new TrieNode();
std::string s = "BANANAS";
for (int i = 0; i < s.size(); ++i) {
// printf("%s\n", s.substr(i).c_str());
ptn->insert(s.substr(i).c_str());
}
TrieNode* ptn0 = ptn->find("NAS");
if (ptn0)
printf("%s is in", "NAS");
delete ptn;
}
示例8: insert
// Inserts a word into the trie.
void insert(string word) {
TrieNode* node = root;
for(int i = 0; i < word.length(); i++)
{
TrieNode* nextNode = node->find(word[i]);
if(!nextNode)
{
TrieNode* newNode = new TrieNode();
newNode->letter = word[i];
node->next.push_back(newNode);
nextNode = newNode;
}
node = nextNode;
}
TrieNode* newNode = new TrieNode();
newNode->letter = '\0';
node->next.push_back(newNode);
}