#include <stdio.h>
#define LEN 11
void hash_init(int hash_table[])
{
for(int i=0; i<LEN; i++)
{
hash_table[i] = 0;
}
return ;
}
//除留余数法
int hash_fun(int key)
{
return key%LEN;
}
//成功返回0
//失败返回-1
int hash_insert(int hash_table[], int key)
{
int index, index1;
index = hash_fun(key);
if(hash_table[index] == 0)
{
hash_table[index] = key;
return 0;
}
//解决冲突---->线性探测法解决冲突
for(int i=1; i<LEN; i++)
{
index1 = (index+i)%LEN;
if(hash_table[index1] == 0)
{
hash_table[index1] = key;
return 0;
}