-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathHashmap_implemenataion.cpp
116 lines (115 loc) · 2.42 KB
/
Hashmap_implemenataion.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int f(string s)
{
int sum = 0;
for(int i=0;i<s.size();i++)
{
sum+=s[i];
}
return sum%10;
}
class Node{
public:
string val;
Node *next;
Node(string data)
{
val = data;
next = NULL;
}
};
class hp{
public:
Node* arr[10]={NULL};
int size = 10;
void insert(string data)
{
// cout<<"INSIDE INSERT "<<endl;
int index = f(data);
// cout<<"DATA : "<<data<<" Index is : "<<index<<endl;
Node *n = new Node(data);
if(arr[index]==NULL)
{
arr[index]=n;
}
else
{
Node *rest = arr[index]->next;
arr[index]->next=n;
n->next=rest;
}
}
void print()
{
for(int i=0;i<size;i++)
{
while(arr[i]!=NULL)
{
cout<<arr[i]->val<<" -> ";
arr[i]=arr[i]->next;
}
cout<<" NULL "<<endl;
}
}
void search(string data)
{
for(int i=0;i<size;i++)
{
while(arr[i]!=NULL)
{
if(arr[i]->val == data)
{
cout<<" Data "<<arr[i]->val<<" is present at the index "<<i<<endl;
return;
}
arr[i]=arr[i]->next;
}
}
cout<<"Invalid Data : ERROR 404 "<<data<<endl;
}
void del(string data)
{
Node*temp=arr[0];
for(int i=0;i<size;i++)
{
while(temp!=NULL)
{
if(arr[i]->val==data)
{
Node* temp = arr[i];
arr[i]=arr[i]->next;
delete temp;
}
arr[i]=arr[i]->next;
}
}
cout<<"Invalid Data "<<endl;
}
};
int main()
{
hp m;
m.insert("Mudit");
m.insert("Pushkar");
m.insert("Arvind Tripathi");
m.insert("Rachana Tripathi");
m.insert("rishu");
m.insert("sankalp");
m.insert("Rishit");
m.insert("princeS");
m.insert("PrinceK");
m.insert("krishan");
m.insert("nishant");
m.insert("kartikaye");
m.insert("rakshit");
m.insert("mayank");
m.insert("LUV");
m.insert("Ram");
m.insert("komal");
m.insert("aditya");
m.insert("kush");
// m.search("Mudit");
m.print();
}