-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubset.java
More file actions
38 lines (29 loc) · 889 Bytes
/
Subset.java
File metadata and controls
38 lines (29 loc) · 889 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
package com.company.Assign2;
//WAP to check whether an array is a subset of another array
class Subset{
static boolean isSubset(int arr1[], int arr2[], int m, int n)
{
int i = 0;
int j = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (arr2[i] == arr1[j])
break;
}
if (j == m)
return false;
}
return true;
}
public static void main(String args[])
{
int arr1[] = { 11, 10, 13, 21, 30, 70 };
int arr2[] = { 11, 30, 70, 10 };
int m = arr1.length;
int n = arr2.length;
if (isSubset(arr1, arr2, m, n))
System.out.print("arr2[] is subset of arr1[] ");
else
System.out.print("arr2[] is not subset of arr1[] ");
}
}