Template:
#include <string.h>#include<stdio.h>#include<malloc.h>#include<iostream>#include<algorithm>using namespacestd;Const intMAXN = -;structtrie{Trie*NEXT[MAXN]; intv; Inlinevoidinit () { This->v =1; for(intI=0; i<maxn; i++) This->next[i] =NULL; }}; Trie*root = (Trie *)malloc(sizeof(Trie));voidCreatetrie (Char*str) { intLen =strlen (str); Trie*p = root, *tmp; for(intI=0; i<len; i++){ intIDX = str[i]-'a'; if(P->next[idx] = =NULL) {tmp= (Trie *)malloc(sizeof(Trie)); TMP-init (); P->NEXT[IDX] =tmp; }Elsep->next[idx]->v++; P= p->Next[idx]; } P->v =-1;//If the end, then the V is changed to 1, of course, the variables in the dictionary tree are based on the topic//setting and assigning values at a specific location.}intFindtrie (Char*str) { intLen =strlen (str); Trie*p =Root; for(intI=0; i<len; i++){ intIDX = str[i]-'a'; P= p->Next[idx]; //... Perform a series of operations}}inlinevoidDeltrie (Trie *T) { if(T = = NULL)return ; for(intI=0; i<maxn; i++){ if(T->next[i]! =NULL) Deltrie (T-Next[i]); } Free(T); return ;}intMainvoid) {root.init ();//!!! //...}
pointer version
Array Version
Dictionary tree algorithm Reference ==> http://www.cnblogs.com/tanky_woo/archive/2010/09/24/1833717.html
Dictionary tree templates (pointer && array)