コード例 #1
0
        public SetCustom SymmetricExceptWith(SetCustom other)
        {
            SetCustom union     = Union(other);
            SetCustom intersect = IntersectWith(other);

            return(union.ExceptWith(intersect));
        }
コード例 #2
0
 static void Print(SetCustom customSet)
 {
     foreach (var item in customSet)
     {
         Console.Write("{0} ", item);
     }
     Console.WriteLine();
 }
コード例 #3
0
        public SetCustom ExceptWith(SetCustom other)
        {
            SetCustom result = new SetCustom(_items);

            foreach (var item in other)
            {
                result.Remove(item);
            }
            return(result);
        }
コード例 #4
0
        public SetCustom IntersectWith(SetCustom other)
        {
            SetCustom result = new SetCustom();

            foreach (var item in _items)
            {
                if (other.Contains(item))
                {
                    result.Add(item);
                }
            }
            return(result);
        }
コード例 #5
0
        //Deleting elements from the Set - see above (Method Remove)

        //Determining the existance of the element in the Set - see above (Method Contains)

        //Number of elements in the Set - see above (Property Count)

        //Enumerator - see above (Method GetEnumerator)

        #region Method Union - unions two sets
        public SetCustom Union(SetCustom other)
        {
            SetCustom result = new SetCustom(_items);

            foreach (var item in other)
            {
                if (!Contains(item))
                {
                    result.Add(item);
                }
            }
            return(result);
        }
コード例 #6
0
        public bool Subset(SetCustom other)
        {
            SetCustom result = new SetCustom(_items);

            foreach (var item in other._items)
            {
                result.Remove(item);
            }

            if (result == null)
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            SetCustom set1 = new SetCustom();
            SetCustom set2 = new SetCustom();
            SetCustom set3 = new SetCustom();

            set1.Add("John");
            set1.Add("Mark");
            set1.Add("Fred");
            set1.Add("Julie");
            set1.Add(1);
            set1.Add(2);
            set1.Add(3);
            set1.Add(4);
            set1.Add(5);
            Console.WriteLine(new string('-', 60));
            int [] array = { 4, 5, 6, 7 };
            set2.AddRange(array);
            set2.Add("Mark");
            set2.Add("Fred");
            set2.Add("James");
            Console.WriteLine(new string('-', 60));

            //Union
            Console.Write("\nPrinting the set1: ");
            Print(set1);

            Console.Write("\nPrinting the set2: ");
            Print(set2);

            Console.WriteLine("Union:");
            set3 = set1.Union(set2);
            Print(set3);

            //Difference
            Console.WriteLine(new string('-', 60));
            Console.Write("\nPrinting the set1: ");
            Print(set1);

            Console.Write("\nPrinting the set2: ");
            Print(set2);

            Console.WriteLine("Difference:");
            set3 = set1.ExceptWith(set2);
            Console.Write("\nPrinting the set3:  ");
            Print(set3);

            //Intersection
            Console.WriteLine(new string('-', 60));
            Console.Write("\nset1:   ");
            Print(set1);

            Console.Write("\nset2:   ");
            Print(set2);

            Console.WriteLine("Intersection:");
            set3 = set1.IntersectWith(set2);
            Console.Write("\nset3:    ");
            Print(set3);

            //Symmetric Difference
            Console.WriteLine(new string('-', 60));
            Console.Write("\nset1:   ");
            Print(set1);

            Console.Write("\nset2:   ");
            Print(set2);

            Console.WriteLine("Symmetric Difference:");
            set3 = set1.SymmetricExceptWith(set2);
            Console.Write("\nset3:    ");
            Print(set3);

            //Subset?
            Console.WriteLine(new string('-', 60));
            Console.Write("\nset1:   ");
            Print(set1);

            Console.Write("\nset2:   ");
            Print(set2);

            Console.WriteLine("Is the set1 a subset of set2?:   {0}", set1.Subset(set2));
        }