<<字典树模板>>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
//字典树的数据结构
struct Trie{
Trie *child[26];//这里数组的大小看是小写字母还是数字还是都有
int num;
Trie(){//初始化
num = 0;
memset(child , 0 , sizeof(child));
}
};
Trie *root;
//字典树的构建
void Tree_Insert(char *str){
Trie *s = root;
int i = 0;
while(str[i]){
int id = str[i] -'a' ;
if(s -> child[id] == 0)//如果该字节点的字节点为空则要创建中间节点
s -> child[id] = new Trie();
s = s -> child[id];
s -> num++;
i++;
}
}
//字典树的查找
int Tree_Find(char *str){
Trie *s = root;
int count ;
while(str[i]){
int id = str[i] - 'a';
if(s -> child[id] == 0){//如果当前指针s的对应于当前字符str[i]在字母表的位置的子节点为空
return count;//直接返回0
}
else{
s = s -> child[id];
count = s -> num ;
}
i++;
}
return count;
}
int main(){
int i , j;
//建立一个root分配空间
root = new Trie();
return 0;
}