Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }