-
Notifications
You must be signed in to change notification settings - Fork 10
/
Hashing.cpp
38 lines (31 loc) · 1001 Bytes
/
Hashing.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
# https://www.facebook.com/dikshit.kaushal.564/posts/103324861581146
# Subscribed by Dikshit Kaushal
#include<bits/stdc++.h>
using namespace std;
// This function prints all distinct elements
bool areDisjoint(int set1[], int set2[], int n1, int n2)
{
// Creates an empty hashset
set<int> myset;
// Traverse the first set and store its elements in hash
for (int i = 0; i < n1; i++)
myset.insert(set1[i]);
// Traverse the second set and check if any element of it
// is already in hash or not.
for (int i = 0; i < n2; i++)
if (myset.find(set2[i]) != myset.end())
return false;
return true;
}
// Driver method to test above method
int main()
{
int set1[] = {10, 5, 3, 4, 6};
int set2[] = {8, 7, 9, 3};
int n1 = sizeof(set1) / sizeof(set1[0]);
int n2 = sizeof(set2) / sizeof(set2[0]);
if (areDisjoint(set1, set2, n1, n2))
cout << "Yes";
else
cout << "No";
}