-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
47 lines (44 loc) · 902 Bytes
/
Copy path1.cpp
File metadata and controls
47 lines (44 loc) · 902 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
// C++ program to demonstrate implementation of our
// own hash table with chaining for collision detection
#include<bits/stdc++.h>
using namespace std;
struct MyHash
{
int BUCKET;
list<int> *table;
MyHash(int b)
{
BUCKET = b;
table = new list<int>[BUCKET];
}
void insert(int k)
{
int i = k % BUCKET;
table[i].push_back(k);
}
bool search(int k)
{
int i = k % BUCKET;
for (auto x : table[i])
if (x == k)
return true;
return false;
}
void remove(int k)
{
int i = k % BUCKET;
table[i].remove(k);
}
};
// Driver method to test Map class
int main()
{
MyHash mh(7);
mh.insert(10);
mh.insert(20);
mh.insert(15);
mh.insert(7);
cout << mh.search(10) << endl;
mh.remove(15);
cout << mh.search(15);
}