欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

12.17`

程序员文章站 2022-03-08 16:44:22
...

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 11
#define KEY 11

void Hash_Insert(int Hash[],int x)
{
int i=0,t,c=0,ave;
t=x%KEY;
while(i<MAXSIZE)
{

    if(Hash[t]<=-1)
    {
        Hash[t]=x;
        i++;
        break;
    }
    else
        t=(t+1)%KEY;
    c++;

}
if(i==MAXSIZE)
    printf("Hash is full\n");
ave = c*1.0/i;
printf("ave is%d",ave);

}

void Hash_Search(int Hash[],int x)
{
int i=0,t;
t=x%KEY;
while(Hash[t]!=-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]
-1||i=MAXSIZE)
printf(“no found\n”);
}

void Hash_Delelt(int Hash[],int x)
{
int i=0,t;
t=x%KEY;
while(Hash[t]!=-1&&i<MAXSIZE)
{
if(Hash[t]x)
{
Hash[t]=-2;
printf("%d in Hash list is deleted \n",x);
break;
}
else
t=(t+1)%KEY;
i++;
}
if(i
MAXSIZE)
printf(“delete fail\n”);

}

int main()
{

return 0;

}

相关标签: Hash