码迷,mamicode.com
首页 > 其他好文 > 详细

字典树(指针 找单词)

时间:2018-05-27 12:12:32      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:next   root   node   class   style   ext   char   null   arc   

struct node
{
    node *next[28];
    bool is;
    node()
    {
        is=false;
        memset(next,0,sizeof(next));
    }
};
void insert(node *root,char s[])
{
    int i=0;
    node *p=root;
    while(s[i])
    {
        int j=s[i++]-a;
        if(p->next[j]==NULL) p->next[j]=new node();
        p=p->next[j];
    }
    p->is=true;
}
int search(node *root,char s[])
{
    i=0,len=0;
    node *p=root;
    while(s[i])
    {
        int j=s[i++]-a;
        if(p->next[j]==NULL) return 0;  //查不到
        p=p->next[j];
    }
    return 1;
}

 

字典树(指针 找单词)

标签:next   root   node   class   style   ext   char   null   arc   

原文地址:https://www.cnblogs.com/ww123/p/9095196.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!