字典树的学习
#include <bits/stdc++.h> #define maxn 100005 using namespace std; typedef struct Trie_node { int cnt; struct Trie_node *next[26]; bool exist; }Trie_node,*Trie; Trie_node *createTrienode() { Trie_node *node =(Trie_node *)malloc(sizeof(Trie_node)); node->cnt=0; node->exist=false; memset(node->next,0,sizeof(node->next)); return node; } void Trie_insert(Trie root ,char *word) { Trie node =root; char *p=word; int id; while(*p) { id=*p-'a'; if(node->next[id]==NULL) { node->next[id]=createTrienode(); } node=node->next[id]; ++p; node->cnt+=1; } node->cnt+=1; node->exist=true; } int Trie_search(Trie root ,char *word) { Trie node=root; char *p=word; int id; while(*p) { id=*p-'a'; node=node->next[id]; ++p; if(node->next[id]==NULL) return 0; } return node->cnt; }