#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <math.h>
#define MOD 1000000007
using namespace std;
const int M = 100000;
struct node{
int next[26];
int value;
bool end;
};
node tree[M];
int pi = 1;
void init(){
memset(tree,0,sizeof(tree));
pi = 1;
}
void insert(char *keyword,int value){
int index,p,i;
for(i=p=0;keyword[i]; ++i){
index = keyword[i]-'a';
if(tree[p].next[index]==0){
tree[p].next[index] = pi++;
}
p = tree[p].next[index];
}
tree[p].value = value;
tree[p].end = 1;
}
bool query(char *keyword,int &value){
int index,p,i;
for(i=p=0;keyword[i]; ++i){
index = keyword[i]-'a';
if(tree[p].next[index]==0){
return false;
}
p = tree[p].next[index];
}
if(tree[p].end){
value = tree[p].value;
return true;
}
return false;
}
int main()
{
return 0;
}
字典树模板
最新推荐文章于 2017-02-04 14:35:02 发布