/// <summary> /// Make union of this set and secondSet. /// </summary> /// <param name="secondSet"> Second set to union. </param> /// <returns> New set - union of the sets. </returns> public ADTset <ElementType> Union(ADTset <ElementType> secondSet) { var unionSet = new ADTset <ElementType>(); for (var tempThis = head; tempThis != null; tempThis = tempThis.Next()) { unionSet.Add(tempThis.Value()); } for (var tempSecondSet = secondSet.head; tempSecondSet != null; tempSecondSet = tempSecondSet.Next()) { unionSet.Add(tempSecondSet.Value()); } return(unionSet); }
/// <summary> /// Make intersection os this set and secondSet. /// </summary> /// <param name="secondSet"> Second set to intersection. </param> /// <returns> New set - intersection of sets. </returns> public ADTset <ElementType> Intersection(ADTset <ElementType> secondSet) { var intersectionSet = new ADTset <ElementType>(); var tempThis = head; var tempSecondSet = secondSet.head; while (tempSecondSet != null && tempThis != null) { if (tempThis.Value().CompareTo(tempSecondSet.Value()) == 0) { intersectionSet.Add(tempThis.Value()); tempThis = tempThis.Next(); tempSecondSet = tempSecondSet.Next(); } else if (tempThis.Value().CompareTo(tempSecondSet.Value()) < 0) { tempThis = tempThis.Next(); } else { tempSecondSet = tempSecondSet.Next(); } } return(intersectionSet); }