/// <summary> /// This function finds the union between two IntegerSet objects and returns the set. /// </summary> /// <param name="otherSet">The other IntegerSet object.</param> /// <returns>The resultant set which contains the union of the two sets.</returns> public IntegerSet Union(IntegerSet otherSet) { IntegerSet resultSet = new IntegerSet(); int counter = 0; foreach (bool value in otherSet.Set) { if (value) { resultSet.Set[counter] = true; } else if (_set[counter]) { resultSet.Set[counter] = true; } counter++; } return(resultSet); }
/// <summary> /// This function finds the intersection between two IntegerSet objects and returns the set. /// </summary> /// <param name="otherSet">The other IntegerSet object.</param> /// <returns>The resultant set which contains the intersection of the two sets.</returns> public IntegerSet Intersection(IntegerSet otherSet) { IntegerSet result = new IntegerSet(); checked { int counter = 0; foreach (bool value in otherSet.Set) { if (value == true && _set[counter] == true) { result._set[counter] = true; } counter++; } } // Must use exception handling return(result); }
/// <summary> /// This function finds the union between two IntegerSet objects and returns the set. /// </summary> /// <param name="otherSet">The other IntegerSet object.</param> /// <returns>The resultant set which contains the union of the two sets.</returns> public IntegerSet Union(IntegerSet otherSet) { // TODO Write the Union Method // Must use foreach // Must use exception handling try { bool[] _tempSet = new bool[_size]; uint i = 0; foreach (bool temp in otherSet.Set) { _tempSet[i] = _set[i] || temp; i++; } return(new IntegerSet(_tempSet)); } catch (Exception e) { Console.WriteLine(e); } return(new IntegerSet()); //if something happened, create a new empty set and return it }
/// <summary> /// This function finds the union between two IntegerSet objects and returns the set. /// </summary> /// <param name="otherSet">The other IntegerSet object.</param> /// <returns>The resultant set which contains the union of the two sets.</returns> public IntegerSet Union(IntegerSet otherSet) { IntegerSet result = new IntegerSet(); int counter = 0; foreach (bool value in otherSet.Set) { if (value) { result.Set[counter] = true; } else if (Set[counter]) { result.Set[counter] = true; } counter++; } // Must use exception handling return(result); }