zoukankan      html  css  js  c++  java
  • Hash模板

    const int mod = 9973;//一般为靠近总数的素数
    struct Hashtable
    {
        int x;//hash存的值
        Hashtable * next;
        Hashtable()
        {
            next = 0;
        }
    };
    Hashtable * Hash[mod];
    void Hash_Insert(int x)//存x
    {
        int key = x % mod;//hash函数,根据情况而定
        if(!Hash[key])//该key第一个元素
        {
            Hashtable * p = new Hashtable;
            p->x = x;
            Hash[key] = p;
        }
        else
        {
            Hashtable *p = Hash[key];
            while(p->next)p=p->next;
            Hashtable* temp = new Hashtable;
            temp->x = x;
            p->next = temp;
        }
    }
    bool Find(int x)
    {
        int key = x % mod;
        if(!Hash[key])return false;
        else
        {
            Hashtable * temp = Hash[key];
            while(temp)
            {
                if(temp->x == x)
                    return true;
                temp = temp->next;
            }
        }
        return false;
    }
  • 相关阅读:
    C++内存管理
    GitHub 简单用法
    Tembin
    git
    js 插件使用总结
    cas sso
    Redis实战
    全面分析 Spring 的编程式事务管理及声明式事务管理
    mybatis
    b2b
  • 原文地址:https://www.cnblogs.com/fzl194/p/8949505.html
Copyright © 2011-2022 走看看