Пример #1
0
        public EasySet <T> Intersection(EasySet <T> set)
        {
            return(new EasySet <T>(items.Intersect(set.items)));

            var         result = new EasySet <T>();
            EasySet <T> big;
            EasySet <T> small;

            if (Count >= set.Count)
            {
                big   = this;
                small = set;
            }
            else
            {
                big   = set;
                small = this;
            }

            foreach (var item1 in small.items)
            {
                foreach (var item2 in big.items)
                {
                    if (item1.Equals(item2))
                    {
                        result.Add(item1);
                        break;
                    }
                }
            }
            return(result);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var easySet1 = new EasySet <int>(new int[] { 1, 2, 3, 4, 5 });
            var easySet2 = new EasySet <int>(new int[] { 4, 5, 6, 7, 8 });
            var easySet3 = new EasySet <int>(new int[] { 3, 4, 5 });


            Console.Write("Union: ");
            foreach (var item in easySet1.Union(easySet2))
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Console.Write("Intersection: ");
            foreach (var item in easySet1.Intersection(easySet2))
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Console.Write("Difference A \\ B: ");
            foreach (var item in easySet1.Difference(easySet2))
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Console.Write("Difference B \\ A: ");
            foreach (var item in easySet2.Difference(easySet1))
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Console.Write("A Subset C: ");
            Console.WriteLine(easySet1.Subset(easySet3));

            Console.Write("C Subset A: ");
            Console.WriteLine(easySet3.Subset(easySet1));

            Console.Write("C Subset B: ");
            Console.WriteLine(easySet3.Subset(easySet2));


            Console.Write("SymmetricDifference: ");
            foreach (var item in easySet1.SymmetricDifference(easySet2))
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Console.ReadLine();
        }
Пример #3
0
        public EasySet <T> Difference(EasySet <T> set)
        {
            return(new EasySet <T>(items.Except(set.items)));

            var result = new EasySet <T>(items);

            foreach (var item in set.items)
            {
                result.Remove(item);
            }
            return(result);
        }
Пример #4
0
        public EasySet <T> Union(EasySet <T> set)
        {
            EasySet <T> result = new EasySet <T>();

            return(new EasySet <T>(items.Union(set.items)));
            //foreach(var item in items)
            //{
            //    result.Add(item);
            //}
            //foreach(var item in set.items)
            //{
            //    result.Add(item);
            //}
            //return result;
        }
Пример #5
0
        public EasySet <T> SymmetricDifference(EasySet <T> set)
        {
            // return new EasySet<T> (items.Except(set.items).Union(set.items.Except(items)));
            var result = new EasySet <T>();

            foreach (var item1 in items)
            {
                var equals = false;
                foreach (var item2 in set.items)
                {
                    if (item1.Equals(item2))
                    {
                        equals = true;
                        break;
                    }
                }
                if (equals == false)
                {
                    result.Add(item1);
                }
            }
            foreach (var item1 in set.items)
            {
                var equals = false;

                foreach (var item2 in items)
                {
                    if (item1.Equals(item2))
                    {
                        equals = true;

                        break;
                    }
                }
                if (equals == false)
                {
                    result.Add(item1);
                }
            }
            return(result);
        }
Пример #6
0
        public bool Subset(EasySet <T> set)
        {
            // return items.All(i => set.items.Contains(i));

            foreach (var item1 in items)
            {
                var equals = false;
                foreach (var item2 in set.items)
                {
                    if (item1.Equals(item2))
                    {
                        equals = true;
                        break;
                    }
                }
                if (!equals)
                {
                    return(false);
                }
            }
            return(true);
        }