-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHashing.c
More file actions
60 lines (57 loc) · 918 Bytes
/
Copy pathHashing.c
File metadata and controls
60 lines (57 loc) · 918 Bytes
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
51
52
53
54
55
56
57
58
59
60
#include<stdio.h>
#define SIZE 10
void Insert(int H[],int key)
{
int index=Hash(key);
if(H[index]!=0)
{
int k=probe(H,key,index);
H[k]=key;
}
else
{
H[index]=key;
}
}
int Hash(int key)
{
int y=key%SIZE;
return y;
}
int probe(int H[],int key,int index)
{
int i=0;
while(H[(Hash(key)+i)%SIZE]!=0)
{
i++;
}
return (index+i)%10;
}
int search(int H[],int key)
{
int i=0;
int index=Hash(key);
while(H[(index+i)%SIZE]!=key)
{
i++;
}
return index+i+1;
}
void main()
{
int HT[10]={0};
Insert(HT,12);
Insert(HT,32);
Insert(HT,45);
Insert(HT,67);
Insert(HT,90);
Insert(HT,47);
Insert(HT,18);
int i;
for(i=0;i<10;i++)
{
printf("%d\n",HT[i]);
}
int c=search(HT,12);
printf("%d",c);
}