-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis_disjoint.c
More file actions
44 lines (39 loc) · 856 Bytes
/
is_disjoint.c
File metadata and controls
44 lines (39 loc) · 856 Bytes
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
/*
* Author: Robert Dragan
* Github: nucata
* Date: 03-10-2022
* Description: Compares two arrays to see if they have any item in common.
*/
#include <stdio.h> // printf
#include "functions.h" //test_int
int is_disjoint(int *arr1, int len1, int *arr2, int len2) {
int counter = 0;
int i = 0;
int j;
while (i < len1) {
j = 0;
while (j < len2) {
if (arr1[i] == arr2[j]) {
return (1);
}
j++;
counter++;
}
i++;
}
return (0);
}
int main(void) {
int a[] = {1, 2, 3, 4};
int b[] = {5, 0, 6, 4};
int c[] = {4};
int d[] = {-1, -2, 5, 8};
test_int(is_disjoint(a, 4, b, 4), 1);
test_int(is_disjoint(a, 4, c, 1), 1);
test_int(is_disjoint(b, 4, c, 1), 1);
test_int(is_disjoint(a, 4, d, 4), 0);
test_int(is_disjoint(c, 4, d, 4), 0);
test_int(is_disjoint(d, 4, b, 4), 1);
test_int(is_disjoint(a, 4, b, 4), 1);
return (0);
}