#include <stdio.h>
#include <stdlib.h>
#define DATANUM 8
#define HASHLENGH 11
int FindHashfunction(int elem)
{
return ((3*elem)%11);
}
void GetHash(int H[], int elemlist[])
{
int position, flag, asl = 0;
for(int i=0; i<DATANUM; i++){
flag = 1;
position = FindHashfunction(elemlist[i]);
while(H[position]!=0){
position++;
flag++;
}
asl += flag;
H[position] = elemlist[i];
}
asl = asl/DATANUM;
printf("%d", asl);
}
int main()
{
int elemlist[DATANUM] = {22,41,53,46,30,13,01,67};
int H[HASHLENGH] = {0};
GetHash(H, elemlist);
return 0;
}
西北工业大学-数据结构NOJ-23构造哈希表
最新推荐文章于 2024-09-07 18:43:14 发布