Hash查找

1.哈希表的创建

 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 }
View Code

2.哈希表的查找

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 }
View Code

3.哈希表的删除

 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 }
View Code

4.哈希表的插入

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 }
View Code

 

转载于:https://www.cnblogs.com/xyzyj/p/6642057.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值