閉散列表上的插入、查詢和刪除演算法
阿新 • • 發佈:2018-11-26
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 11 //雜湊表對的長度
#define key 11 // 除留取餘法
void Hash__Insert(int Hash[],int x)
{
int i=0,t;
t=x%key;
while(i<MAXSIZE)
{
if(Hash[i]<=-1)
{
Hash[i]=x;
break;
}
else
t=(t+1)%key;
}
}
void Hash_Search(int Hash[],int x)
{
int i=0,t;
t=x%key;
while(Hash[i]!=-1&&i<MAXSIZE)
{
if(Hash[t]x)
{
printf(“Hash position of %d is %d\n”,x,t);
break;
}
else
t=(t+1)%key;
i++;
}
if(Hash[t]
printf(“no found \n”);
}
void Hash_Delete(int Hash[],int x)
{
int i,t;
t=x%key;
while(Hash[i]!=-1&&i<MAXSIZE)
{
if(Hash[i]==x)
{
Hash[t]=-2;
printf("%d in hashlist is deleted !\n");
break;
}
else
t=(t+1)%key;
i++;
}
if(i==MAXSIZE)
printf("Delete fail\n");
}
int main()
{
printf(“Hello world!\n”);
return 0;
}