简单好用的哈希表

哈希表板子

以后考试不要总自己发挥妄图创造模板。。

 1 struct Hsh{
 2 int head[N1],to[M1],nxt[M1],val[M1],cte;
 3 void ins(int x,int w)
 4 {
 5     int u=x%maxn,j,v;
 6     for(j=head[u];j;j=nxt[j])
 7     {
 8         v=to[j];
 9         if(v==x) return;
10     }
11     cte++; to[cte]=x; nxt[cte]=head[u];
12     head[u]=cte; val[cte]=w;
13 }
14 int find(int x)
15 {
16     int u=x%maxn,j,v;
17     for(j=head[u];j;j=nxt[j])
18     {
19         v=to[j];
20         if(v==x) return val[j];
21     }
22     return -1;
23 }
24 };

猜你喜欢

转载自www.cnblogs.com/guapisolo/p/10252234.html