zoukankan      html  css  js  c++  java
  • 字典树模板

    const int N=27;
    
    struct node{
        int cnt;
        node* childs[N];
        node(){
            cnt=0;
            for(int i=0;i<N;i++)
                childs[i]=NULL;
        }
    };
    
    node *root=new node();
    node *current,*newnode;
    
    void insert(char *str){
        current=root;
        for(int i=0;i<strlen(str);i++){
            int m=str[i]-'a';
            if(current->childs[m]!=NULL){
                current=current->childs[m];
                ++(current->cnt);
            }else{
                newnode=new node;
                ++(newnode->cnt);
                current->childs[m]=newnode;
                current=newnode;
            }
        }
    }
    
    int search(char *str){
        current=root;
        for(int i=0;i<strlen(str);i++){
            int m=str[i]-'a';
            if(current->childs[m]==NULL)
                return 0;
            current=current->childs[m];
        }
        return current->cnt;
    }
  • 相关阅读:
    Constructor构造方法
    overload重载
    static关键字
    this关键字
    继承
    ORACLE数据库 常用命令和Sql常用语句
    常见单词
    L贪心基础
    J贪心
    K贪心
  • 原文地址:https://www.cnblogs.com/IKnowYou0/p/6654480.html
Copyright © 2011-2022 走看看