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


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

本文整理汇总了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;
}
开发者ID:MJ111,项目名称:algorithm-snippet,代码行数:8,代码来源:aho-corasick.cpp

示例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;
 }
开发者ID:mkfsn,项目名称:LeetCode,代码行数:10,代码来源:implement-trie-prefix-tree.cpp

示例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;
		}
开发者ID:jinfenglin,项目名称:leetcode,代码行数:17,代码来源:search.cpp

示例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;
 }
开发者ID:mkfsn,项目名称:LeetCode,代码行数:11,代码来源:implement-trie-prefix-tree.cpp

示例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');
 }
开发者ID:mkfsn,项目名称:LeetCode,代码行数:11,代码来源:implement-trie-prefix-tree.cpp

示例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;
		}
开发者ID:jinfenglin,项目名称:leetcode,代码行数:13,代码来源:search.cpp

示例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;
}
开发者ID:iamslash,项目名称:dsalgorithm,代码行数:13,代码来源:a.cpp

示例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);
		}
开发者ID:jinfenglin,项目名称:leetcode,代码行数:22,代码来源:search.cpp


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