0% found this document useful (0 votes)
7 views2 pages

12

The document contains a C program that implements a hash table using linear probing for collision handling. It allows users to input four-digit employee IDs, calculates their hash keys, and stores them in an array while managing collisions. The program also includes functionality to display the contents of the hash table after user inputs are completed.

Uploaded by

muskaanthakur081
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

12

The document contains a C program that implements a hash table using linear probing for collision handling. It allows users to input four-digit employee IDs, calculates their hash keys, and stores them in an array while managing collisions. The program also includes functionality to display the contents of the hash table after user inputs are completed.

Uploaded by

muskaanthakur081
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<stdlib.h>
#define max 100
int create(int num)
{
int key;
key=num%100;
return key;
}
void lp(int a[max],int key,int num)
{
int flag=0,i,count=10;
if(a[key]==-1)
a[key]=num;
else
{
for(i=10;i<max;i++)
{
if(a[i]!=-1)
count++;
}
if(count==max)
{
printf("\n hash table is full\n");
//display(a);
exit(1);
}
for(i=key+1;i<max;i++)
if(a[i]==-1)
{
a[i]=num;
flag=1;
break;
}
for(i=10;i<key&&flag==0;i++)
if(a[i]==-1)
{
a[i]=num;
flag=1;
break;
}
}
}
void display(int a[max])
{
int i;
printf("\n the hash table is…\n");
printf("key/index\t employee id\n");
for(i=10;i<max;i++)
printf("\n %d %d\n", i, a[i]);
}
int main()
{
int a[max],num,key,i;
int ans;
printf("collision handling by linear probing\n");
for(i=10;i<max;i++)
a[i]=-1;
do
{
printf("\n enter the four digit number");
scanf("%d",&num);
key=create(num);
lp(a,key,num);
printf("do you want to continue?\n");
scanf("%d",&ans);
}while(ans==1);
display(a);
}

You might also like