-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfinaltask4.cpp
More file actions
84 lines (72 loc) · 1.85 KB
/
finaltask4.cpp
File metadata and controls
84 lines (72 loc) · 1.85 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<bits/stdc++.h>
#include<string.h>
#include<list>
using namespace std;
const int tablesize = 10; //Initializing the table size of the Hashtable
class Hash_table {
private:
int GRs[tablesize];
string Names[tablesize];
public:
int Hashfunct(int GR_No);
void insertKey(int GR_No , string name); //The GR number is the the key and the name is the value
void deleteKey(int GR_No);
void modifyKey(int GR_No , string name);
int searchKey(int GR_No);
void print();
void print_key_value(int GR_No);
Hash_table() {
for (int i = 0; i<tablesize; i++) {
GRs[i] = 0;
}
}
};
int Hash_table::Hashfunct(int GR_No)
{
return (GR_No) % tablesize;
}
void Hash_table::insertKey(int GR_No, string name) {
int index = Hashfunct(GR_No);
while (GRs[index] != 0 && GRs[index] != GR_No) {
index = Hashfunct(index + 1);
}
GRs[index] = GR_No;
Names[index] = name;
}
int Hash_table::searchKey(int GR_No)//Function for searching a key.
{
int i;
int count=0;
for(int i=0;i<tablesize;i++)
{
if(GRs[i]==GR_No)
{
count++;
return i;
break;
}
}
print_key_value(GR_No);
if(count==0)
{
cout<<"Sorry this GR Number is not valid"<<endl;
}
}
void Hash_table::print_key_value(int GR_No)//Function for priting particular key value .
{
int x;
x=searchKey(GR_No);
cout<<"GR Number :"<<GRs[x]<<endl;
cout<<"Name :"<<Names[x]<<endl;
}
int main() {
int x;
int y;
Hash_table h1;
h1.insertKey(11910360,"Prapti");
h1.insertKey(1191022,"Juhi");
h1.insertKey(1191044,"Harshita");
x=h1.searchKey(1191044);
cout<<"Index :"<<x<<endl;
y=h1.searchKey(119103433);
}