It is straightforward and efficient to compute the union of two sets using Boolean values. We may create a new union set by Oring the matching items of the two BitArrays since the union of two sets is a combination of the members of both sets. At other words, if the value in the corresponding place of either BitArray is True, a member is added to the new set. Computing the intersection of two sets is analogous to computing the union, except that the And operator is used instead of the Or operator Using the same technique we used to detect the difference, we can determine if one set is a subset of another. For example, if: setA(index) && !(setB(index)) evaluates to False then setA is not a subset of setB. The BitArray Set Implementation Write The code for a CSet class based on a BitArray.
It is straightforward and efficient to compute the union of two sets using Boolean values. We may create a new union set by Oring the matching items of the two BitArrays since the union of two sets is a combination of the members of both sets. At other words, if the value in the corresponding place of either BitArray is True, a member is added to the new set.
Computing the intersection of two sets is analogous to computing the union, except that the And operator is used instead of the Or operator
Using the same technique we used to detect the difference, we can determine if one set is a subset of another.
For example, if:
setA(index) && !(setB(index))
evaluates to False then setA is not a subset of setB.
The BitArray Set Implementation
Write The code for a CSet class based on a BitArray.
Step by step
Solved in 2 steps