-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashing_practise.cpp
More file actions
59 lines (52 loc) · 1.09 KB
/
hashing_practise.cpp
File metadata and controls
59 lines (52 loc) · 1.09 KB
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
#include <bits/stdc++.h>
using namespace std;
int arr[11] = {0};
int size = 0;
int rehash1 = 3;
int hasha(int a){
return a%11;;
}
int rehasha(int a){
return (a%11)+rehash1;
}
void insert1(int x){
if(size==11){
cout<<"FULL"<<endl;
}
int hashNum = hasha(x);
while(arr[hashNum] != 0){
hashNum = rehasha(hashNum);
}
arr[hashNum] = x;
size++;
}
void search(int x){
int key = x%11;
int indx;
for(int i=0; i<11; i++){
indx = key+i;
if(arr[indx]==x){
cout<<"Fount it."<<endl;
break;
}
if(i==10){
cout<<"Item not Found"<<endl;
}
}
}
void print(){
for(int i=0;i<11;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
int main(){
int q;
for(int i=0;i<11;i++){
cin>>q;
insert1(q);
}
print();
search(31);
return 0;
}