struct node
{
bool flag;
node *next[2];
node()
{
next[0]=next[1]=NULL;
flag=false;
}
};
void insert(node *&root ,string word)
{
if(root==NULL) root=new node();
node *p=root;
for(int i=0;i<word.size();i++)
{
p->flag=true;
if(!p->next[word[i]-'0'])
{
p->next[word[i]-'0']=new node();
}
p=p->next[word[i]-'0'];
}
}
bool judge(node *root,string word)
{
if(root==NULL) return false;
node *p=root;
for(int i=0;i<word.size();i++)
{
p=p->next[word[i]-'0'];
}
return p->flag;
}
字典树
最新推荐文章于 2025-03-09 10:32:18 发布