哈希表

来源:互联网 发布:搜索引擎优化排名 编辑:程序博客网 时间:2024/06/08 17:35
#define ll long long#define N 1000007const unsigned long long SMod=1000007;struct hashmap{    struct Edge    {        long long num;        int next;    }edges[2*N];    int tot;    int head[SMod+100];    void init(){        memset(head,-1,sizeof(head));        tot=0;    }    void insert(long long num){        int start=num%SMod;        edges[tot].next=head[start];        edges[tot].num=num;        head[start]=tot++;    }    int Find(long long num){        int start=num%SMod;        int ind;        for(ind=head[start]; ind!=-1; ind=edges[ind].next){            if(edges[ind].num==num)break;        }        return ind;    }}ST;
0 0
原创粉丝点击