-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsep_chain.cpp
More file actions
69 lines (64 loc) · 1.44 KB
/
sep_chain.cpp
File metadata and controls
69 lines (64 loc) · 1.44 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
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
vector< string > h[20];
//////////////////////////////////////////////////
// HASH FUNCTION
//////////////////////////////////////////////////
int hashFunc(string s)
{
int c=0;
for(int i=0;i<s.length();i++)
c+=(int)s[i];
return c%20;
}
///////////////////////////////////////////////////////
//FUNCTION TO INSERT IN HASH TABLE
/////////////////////////////////////////////////////
void insert(string s)
{
int index = hashFunc(s);
h[index].push_back(s);
}
//////////////////////////////////////////////////////
//FUNCTION TO SEARCH FROM HASH TABLE
//////////////////////////////////////////////////////
void search(string s)
{
int index = hashFunc(s);
for(int i=0;i<h[index].size();i++)
{
if(h[index][i]==s)
{
cout<<s<<" present in table\n";
return ;
}
}
cout<<s<<" not present\n";
}
////////////////////////////////////////////////////////
//FUNCTION TO DELETE FROM HASH TABLE
////////////////////////////////////////////////////////
void del(string s)
{
int index = hashFunc(s);
for(int i=0;i<h[index].size();i++)
{
}
cout<<s<<" not present\n";
}
/////////////////////////////////////////////////////////
// DRIVER PROGRAM
////////////////////////////////////////////////////////
int main(void)
{
string s[100];
cout<<"enter strings\n";
for(int i=0;i<3;i++)cin>>s[i],insert(s[i]);
cout<<"enter string to search\n";
string v;
cin>>v;
search(v);
//del(v);
}