Esempio n. 1
0
        static void Main(string[] args)
        {
            //// Реализация .NET
            //HashSet<int> set = new HashSet<int>();

            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: {easyset1.Subset(easyset3)}");

            Console.WriteLine();

            Console.Write($"C Subset A: {easyset3.Subset(easyset1)}");

            Console.WriteLine();

            Console.Write($"C Subset B: {easyset3.Subset(easyset2)}");

            Console.WriteLine();

            Console.Write("SymmetricDifference: ");
            foreach (var item in easyset1.SymmetricDifference(easyset2))
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine();

            Console.ReadLine();
        }
Esempio n. 2
0
        public void EasySetSymmetricDifferenceTest()
        {
            var set  = new EasySet <int>(new int[] { 1, 2, 3, 4, 5 });
            var set2 = new EasySet <int>(new int[] { 4, 5, 6, 7, 8 });

            var result = set.SymmetricDifference(set2);

            Assert.AreEqual("1 2 3 6 7 8 ", result.ToString());
            Assert.AreEqual(6, result.Count);
        }
        static void Main(string[] args)
        {
            //HashSet<int> set = new HashSet<int>(); - готовая структура

            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.WriteLine("Union");
            foreach (var item in easySet1.Union(easySet2))
            {
                Console.WriteLine(item + " ");
            }
            Console.WriteLine();
            Console.WriteLine("Intersection");
            foreach (var item in easySet1.Intersection(easySet2))
            {
                Console.WriteLine(item + " ");
            }
            Console.WriteLine();
            Console.WriteLine("Differenct A \\ B");
            foreach (var item in easySet1.Difference(easySet2))
            {
                Console.WriteLine(item + " ");
            }
            Console.WriteLine();
            Console.WriteLine("Differenct B \\ a");
            foreach (var item in easySet2.Difference(easySet1))
            {
                Console.WriteLine(item + " ");
            }
            Console.WriteLine();
            Console.WriteLine("Subset A C");
            Console.WriteLine(easySet1.Subset(easySet3));

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

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

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

            Console.ReadLine();
        }