字典树-模板

简介: //字典树-模板#include<iostream>#include<algorithm>#include<string>#include<fstream>#include<vector>using namespace std;#define N 26#define Offset 'a'typedef st
//字典树-模板
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>
#include<vector>
using namespace std;


#define N 26
#define Offset 'a'

typedef struct TrieNode
{
	bool isword;
	TrieNode *next[N];
	TrieNode(){
		this->isword = false;
		for (int i = 0; i < N; i++) this->next[i] = NULL;
	}
}*Trie;

Trie tree = NULL;

void  InsertElement(const string& str){
	Trie root = tree;
	int i = 0;
	int ch;
	TrieNode* nextNode;
	while (i < str.size()){
		ch = str[i] - Offset;
		nextNode = root->next[ch];
		if (nextNode == NULL){
			nextNode = root->next[ch] = new TrieNode;
		}
		root = nextNode;
		i++;
	}
	root->isword = true;
}

目录
相关文章
|
4月前
树状数组模板
树状数组模板
33 0
|
3月前
|
Java Python
二分查找模板
二分查找模板
|
4月前
线段树模板
线段树模板
40 0
|
机器学习/深度学习
P1873 砍树(二分查找模板)
P1873 砍树(二分查找模板)
93 0
|
存储 人工智能 算法
Trie树模板与应用
Trie树模板与应用
82 0
Trie树模板与应用
洛谷—模板字典树 P8306
洛谷—模板字典树 P8306
72 0
|
算法
kmp算法模板
临近期末了,要开始复习了,先复习一下数据结构的kmp算法吧
二分搜索的三种模板
二分搜索的三种模板
62 0
|
存储 算法
线段树模板与练习
线段树模板与练习
94 0