本文整理汇总了C++中TrieNode::getNext方法的典型用法代码示例。如果您正苦于以下问题:C++ TrieNode::getNext方法的具体用法?C++ TrieNode::getNext怎么用?C++ TrieNode::getNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrieNode
的用法示例。
在下文中一共展示了TrieNode::getNext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findWords
vector<string> findWords(vector<vector<char> >& board, vector<string>& words) {
vector<string> ans;
if (board.empty() || board[0].empty() || words.empty())
return ans;
TrieNode* root = buildTrieTree(words);
for (int i=0; i<board.size(); i++) {
for (int j=0; j<board[0].size(); j++) {
if (root->getNext(board[i][j]) != NULL) {
dfs(ans, board, i, j, root->getNext(board[i][j]), "");
}
}
}
destroyTrieTree(root);
return ans;
}
示例2: buildTrieTree
TrieNode* buildTrieTree(vector<string>& words) {
TrieNode* root = new TrieNode();
for (string word : words) {
int index = 0;
TrieNode* cur = root;
while (index < word.size() && cur->getNext(word[index]) != NULL) {
cur = cur->getNext(word[index]);
index++;
}
while (index < word.size()) {
cur->setNext(word[index]);
cur = cur->getNext(word[index]);
index++;
}
cur->setIsWord(true);
}
return root;
}