public SimpleSet <T> Intersection(SimpleSet <T> set) { // return new SimpleSet<T>(_items.Intersect(set._items)); var result = new SimpleSet <T>(); SimpleSet <T> big; SimpleSet <T> small; if (Count >= set.Count) { big = this; small = set; } else { big = set; small = this; } foreach (var i in small._items) { foreach (var j in big._items) { if (i.Equals(j)) { result.Add(i); break; } } } return(result); }
public SimpleSet <T> Intersection(SimpleSet <T> secondSet) { SimpleSet <T> newSet = new SimpleSet <T>(); List <T> bigger; List <T> smaller; if (this.Count >= secondSet.Count) { bigger = this.items; smaller = secondSet.items; } else { bigger = secondSet.items; smaller = this.items; } foreach (var item1 in smaller) { foreach (var item2 in bigger) { if (item1.Equals(item2)) { newSet.Add(item1); break; } } } return(newSet); }
public SimpleSet <T> Difference(SimpleSet <T> secondSet) { SimpleSet <T> newSet = new SimpleSet <T>(items); foreach (var item in secondSet.items) { newSet.Remove(item); } return(newSet); }
public SimpleSet <T> Difference(SimpleSet <T> set) { // return new SimpleSet<T>(_items.Except(set._items)); var result = new SimpleSet <T>(_items); foreach (var item in set._items) { result.Remove(item); } return(result); }
public SimpleSet <T> Union(SimpleSet <T> secondSet) { SimpleSet <T> simpleSet = new SimpleSet <T>(); foreach (var items in items) { simpleSet.Add(items); } foreach (var items in secondSet.items) { simpleSet.Add(items); } return(simpleSet); }
public SimpleSet <T> Union(SimpleSet <T> set) { // return new SimpleSet<T>(_items.Union(set._items)); var result = new SimpleSet <T>(); foreach (var item in _items) { result.Add(item); } foreach (var item in set._items) { result.Add(item); } return(result); }
public SimpleSet <T> SymmetricDifference(SimpleSet <T> secondSet) { SimpleSet <T> newSet = new SimpleSet <T>(); foreach (var item1 in this.items) { var Equals = false; foreach (var item2 in secondSet.items) { if (item1.Equals(item2)) { Equals = true; break; } } if (Equals == false) { newSet.Add(item1); } } foreach (var item1 in secondSet.items) { bool Equals = false; foreach (var item2 in this.items) { if (item1.Equals(item2)) { Equals = true; break; } } if (Equals == false) { newSet.Add(item1); } } return(newSet); }
public bool Subset(SimpleSet <T> set) { // return _items.All(i => set._items.Contains(i)); foreach (var item in _items) { var equals = false; foreach (var item2 in set._items) { if (item.Equals(item2)) { equals = true; break; } } if (!equals) { return(false); } } return(true); }
public bool Subset(SimpleSet <T> secondSet) { foreach (var item1 in items) { bool Equalse = false; foreach (var item2 in secondSet.items) { if (item1.Equals(item2)) { Equalse = true; break; } } if (Equalse == false) { return(false); } } return(true); }