Im having trouble coding the complement of a set. For example if Set A (x)= {1, 2, 3, 4} and Set B (y)= {5, 2, 3, 8} The complement should be x-y={1,4} or y-x={5,8}. What should I change in this code to achieve this?
for (i = 0; i < x; i++) {
for (int k = 0; k < y; k++) {
if (a[i] == b[k]) {
flag = 1;
break;
} else {
flag = 0;
}
}
if (flag == 0) {
c[z++] = a[i];
}
}
System.out.print("Complement:");
System.out.print("[ ");
for (i = 0; i < x; i++) {
System.out.print(a[i] + ",");
}
System.out.print(" ]");