/// <summary> /// Do the intersection of two sets /// </summary> /// <param name="set1"></param> /// <param name="set2"></param> /// <returns></returns> public Set Intersect(Set set1, Set set2) { if (set1 == null && set2 == null) { return new Set(); } else if (set1 == null) { return (Set)set2.GetClone(); } else if (set2 == null) { return (Set)set1.GetClone(); } else { Set newSet = new Set(); foreach(int element in set1.list) { if (set2.Contains(element)) { newSet.Add(element); } } return newSet; } }
/// <summary> /// Union two sets /// </summary> /// <param name="set1"></param> /// <param name="set2"></param> /// <returns></returns> public Set Union(Set set1, Set set2) { if (set1 == null && set2 == null) { return new Set(); } else if (set1 == null) { return (Set)set2.GetClone(); } else if (set2 == null) { return (Set)set1.GetClone(); } else { Set newSet = new Set(); foreach (int element in set1.list) { newSet.Add(element); } foreach (int element in set2.list) { newSet.Add(element); } return newSet; } }