1.哈希表的创建
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 void Createht(Hashtable ht, Datatype L[], int n) 2 { 3 int i; 4 for (i = 0; i < HASHSIZE; i++) 5 { 6 ht[i].data.key = NULL; 7 ht[i].times = 0; 8 } 9 for (i = 0; i < n; i++) 10 HashInsert(ht, L[i]); 11 }
2.哈希表的查找
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 int HashSearch(Hashtable ht, Datatype x) 2 { 3 int address; 4 address = HashFunc(x,key); //计算散列地址 5 while (ht[address].data.key!NULL&&ht[address].data.key!x.key) 6 address = Collision(address);//没找到处理冲突 7 if (ht[address].data.key == x.key) return address; 8 else return -1; 9 }
3.哈希表的删除
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 int HashDel(Hashtable ht, Datatype x) 2 { 3 int address; 4 address = HashFunnc(x, key); 5 if (address>=0) 6 { 7 ht[address].datakey = DEL; 8 return 1; 9 } 10 return 0; 11 }
4.哈希表的插入
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 int HashInsert(Hashtable ht, Datatable x) 2 { 3 int address; 4 address = HashFunnc(x, key); 5 if (address >= 0) return 0; 6 ht[-address].data = x; 7 ht[-address].times = 1; 8 return 1; 9 }