//this code is designed by codenation.
//7:32 29/11/2020
#include<stdio.h>
int hash(int key,int size);
int main()
{
int N,i,j,b,element;
printf("enter the size of data : \n");
scanf("%d",&N);
int data[N];
for(i=0;i<N;i++)
{
data[i]=0;
}
for(i=0;i<N;i++)
{
printf("enter the element :\n");
scanf("%d",&element);
b=hash(element,N);
if(data[b]==0)
{
data[b]=element;
}
else
{
for(j=0;j<N;j++)
{
if(data[j]==0)
{
data[j]=element;
break;
}
}
}
}
printf("\nthe data after hashing is :\n");
for(i=0;i<N;i++)
{
printf("%d\n",data[i]);
}
}
int hash(int key,int size)
{
int bucket;
bucket=key%size;
return bucket;
}
//this code is developed by codenation.
Comments
Post a Comment