-
Notifications
You must be signed in to change notification settings - Fork 0
/
HASHING.c
50 lines (50 loc) · 1.08 KB
/
HASHING.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
#define mod(x) x%MAX
void linear_prob(int a[],int num,int key)
{
if(a[key]==-1)
a[key]=num;
else
{
printf("\nCollision detected!!");
int i;
for(i=mod(key+1);i!=key;i=mod(++i))
if(a[i]==-1)
break;
if(i!=key)
{
printf("\nCollision avoided successfully\n");
a[i]=num;
}
else
printf("\nHash table is full\n");
}
}
void display(int a[])
{
short ch,i;
printf("\n1.Filtered display\n2.Display all\nEnter choice:");
scanf("%d",&ch);
printf("\nHash table is :\n");
for(i=0;i<MAX;i++)
if(a[i]>0||ch-1)
printf("%d %d\n",i,a[i]);
}
int main()
{
int a[MAX],num,i;
printf("\nCollision handling by linear probing");
for(i=0;i<MAX;a[i++]=-1);
do
{
printf("\nEnter the data:");
scanf("%4d",&num);
linear_prob(a,num,mod(num));
printf("Do u wish to continue(1/0):");
scanf("%d",&i);
}while(i);
display(a);
return 0;
}