-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGROUP-A-4.cpp
More file actions
202 lines (186 loc) · 3.76 KB
/
GROUP-A-4.cpp
File metadata and controls
202 lines (186 loc) · 3.76 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
SAYALI RAHANE
CLASS- SE A
BATCH- C50
GROUP-A-4.To create ADT that implement the "set" concept.
a. Add (newElement) -Place a value into the set
b. Remove (element) Remove the value
c. Contains (element) Return true if element is in collection
d. Size () Return number of values in collection Iterator () Return an iterator used to loop
over collection
e. Intersection of two sets
f. Union of two sets
g. Difference between two sets
h.Subset */
//header files
#include <iostream>
using namespace std;
int HT1[10]; // for set A
int HT2[10]; // for set B
int size = 10;
void init() //initializes Hash Tables
{
for (int i = 0; i < size; i++)
{
HT1[i] = 0;
HT2[i] = 0;
}
}
void display()
{
int i;
cout << "\n Hash Table No 1";
cout << "\n Index - Key";
for (int i = 0; i < size; i++)
{
cout << "\n " << i << " \t " << HT1[i];
}
cout << "\n Hash Table No 2";
cout << "\n Index - Key";
for (int i = 0; i < size; i++)
{
cout << "\n " << i << " \t " << HT2[i];
}
}
void insertSetA(int key)
{
int index;
index = key % size;
if(HT1[index]== 0)
{
HT1[index] = key;
}
else
{
index = (key + 1) % size;
HT1[index] = key;
}
}
void insertSetB(int key)
{
int index;
index = key % size;
HT2[index] = key;
}
void searchSetA(int key)
{
int index;
cout << "\n Searching " << key << " in Set A";
index = key % size;
if (HT1[index] == key)
{
cout << "\n Key " << key << " Found at :" << index;
}
else
{
cout << "\n Key " << key << " Not Found";
}
}
void searchSetB(int key)
{
int index;
cout << "\n Searching " << key << " in Set B";
index = key % size;
if (HT2[index] == key)
{
cout << "\n Key " << key << " Found at :" << index;
}
else
{
cout << "\n Key " << key << " Not Found";
}
}
void deleteSetA(int key)
{
int index;
cout << "\n Deleting " << key << "From Set A";
index = key % size;
if (HT1[index] == key)
{
HT1[index] = 0;
cout << "\n Deleting " << key << " Found at" << index << " and Deleted";
}
else
{
cout << "\n Key : " << key << " Not Found";
}
}
void deleteSetB(int key)
{
int index;
cout << "\n Deleting " << key << "From Set B";
index = key % size;
if (HT2[index] == key)
{
HT2[index] = 0;
cout << "\n Deleting " << key << " Found at" << index << " and Deleted";
}
else
{
cout << "\n Key : " << key << " Not Found";
}
}
int dup(int val)
{
int i, dupl = 0;
for (i = 0; i < size; i++)
{
if (val == HT1[i])
dupl = 1;
}
return dupl;
}
void unionAB()
{
int i, j;
int C[10];
j = 0;
for (i = 0; i < size; i++)
{
if (HT1[i] != 0) //copy setA in setC
{
C[j] = HT1[i];
j++;
}
}
for (i = 0; i < size; i++)
{
if (HT2[i] != 0) //copy SetA in Set C
{
if (dup(HT2[i]) == 0)
{
C[j] = HT2[i];
j++;
}
}
}
cout << "\n Union of SET-A,B = ";
for (i = 0; i < j; i++)
cout << C[i] << ", ";
}
int main()
{
cout << "\n Initializing the HashTables";
init();
display();
insertSetA(123);
insertSetA(81);
insertSetA(63);
insertSetA(82);
insertSetA(92);
insertSetB(69);
insertSetB(96);
insertSetB(72);
cout << "\n After Inserting the values";
display();
cout << "\n Searching Values";
searchSetA(69);
searchSetB(69);
cout << "\n Deleting Values";
deleteSetA(123);
deleteSetB(96);
display();
cout << "\n Union of Set A and B";
unionAB();
cout << "\n";
}