Esempio n. 1
0
        public static MultiSet operator *(MultiSet op1, MultiSet op2)
        {
            (MultiSet biggest, MultiSet smallest) = op1.MaxElem > op2.MaxElem ? (op1, op2) : (op2, op1);
            MultiSet resultSimpleSet = new MultiSet(biggest.MaxElem);

            for (int i = 0; i <= smallest.MaxElem; i++)
            {
                resultSimpleSet._data[i] = Math.Min(biggest._data[i], smallest._data[i]);
            }
            return(resultSimpleSet);
        }
Esempio n. 2
0
        public static MultiSet operator *(MultiSet lhs, MultiSet rhs)
        {
            var length = Math.Min(lhs.Max, rhs.Max);
            var result = new MultiSet(length);

            for (var i = 0; i < length; i++)
            {
                result._arr[i] = Math.Min(lhs._arr[i], rhs._arr[i]);
            }

            return(result);
        }
Esempio n. 3
0
        public static void MultiSetTest1()
        {
            MultiSet mySet1 = new MultiSet(1);
            MultiSet mySet2 = new MultiSet(10);

            mySet1.FillSet(new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1 });
            mySet1.Print(Console.WriteLine);
            mySet2.FillSet("0 7 8 8 1");
            mySet2.DelElem(8);
            mySet2.DelElem(8);
            mySet2.Print(Console.WriteLine);
            Console.WriteLine();
            MultiSet m1 = (mySet1 + mySet2);
            MultiSet m2 = (mySet1 * mySet2);

            m1.Print(Console.WriteLine);
            m2.Print(Console.WriteLine);
            Console.WriteLine();
            m2.DelElem(0);
            m1.Print(Console.WriteLine);
            m2.Print(Console.WriteLine);
            Console.WriteLine();
            Console.WriteLine(m1[-123]);
            Console.WriteLine();
            for (int i = 0; i < m1.MaxElem; i++)
            {
                if (m1[i] > 0)
                {
                    Console.WriteLine($"{i} - {m1[i]} раз");
                }
            }
            Console.WriteLine();
            try
            {
                m1.AddElem(2134234234);
            }
            catch (ElemOutOfSetExeption e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine();
        }
Esempio n. 4
0
        public static MultiSet operator +(MultiSet lhs, MultiSet rhs)
        {
            var minLength = Math.Min(lhs.Max, rhs.Max);
            var length    = Math.Max(lhs.Max, rhs.Max);
            var result    = new MultiSet(length);

            for (var i = 0; i < minLength; i++)
            {
                result._arr[i] = lhs._arr[i] + rhs._arr[i];
            }

            var biggest = lhs.Max > rhs.Max ? lhs : rhs;

            for (var i = minLength; i < length; i++)
            {
                result._arr[i] = biggest._arr[i];
            }

            return(result);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var s = new SimpleSet(100);

            s.Append(new[] { 1, 2, 3, 4, 10, 11, 100 });
            s.Remove(10);
            Console.WriteLine(s);

            var s2 = new BitSet(20);

            s2.Append("1 2 3 4 20 19 20 18");
            s2.Remove(18);
            Console.WriteLine(s2);

            var s3 = new MultiSet(10);

            s3.Append(new[] { 1, 1, 2, 2, 10, 9, 9 });
            s3.Remove(1);
            s3.Remove(9);
            Console.WriteLine(s3);

            s.Add(101);
        }
Esempio n. 6
0
        public void TestUnionAndIntersection(object args)
        {
            int tmpTypeOfSet = typeOfSet;
            Set set1;
            Set set2;

            SetTypeOfSet(null);
            switch (typeOfSet)
            {
            case 1: { set1 = new SimpleSet(max); set2 = new SimpleSet(max); break; }

            case 2: { set1 = new BitSet(max); set2 = new BitSet(max); break; }

            case 3: { set1 = new MultiSet(max); set2 = new MultiSet(max); break; }

            default:
            { set1 = new SimpleSet(max); set2 = new SimpleSet(max); break; }
            }
            typeOfSet = tmpTypeOfSet;
            Settings.Default.TypeSet = typeOfSet;
            Settings.Default.Save();
            string s1, s2;

            Console.WriteLine("Введите первую строку, с которой будет заполнено множество один");
            s1 = GetCommandString();
            try
            {
                set1.FillSet(s1);
            }
            catch (ElemOutOfSetExeption e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Введите вторую строку, с которой будет заполнено множество два");
            s2 = GetCommandString();
            try
            {
                set2.FillSet(s2);
            }
            catch (ElemOutOfSetExeption e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Объединение множеств:");
            if (set1 is SimpleSet)
            {
                Console.WriteLine(((SimpleSet)set1 + (SimpleSet)set2));
            }
            else if (set1 is BitSet)
            {
                Console.WriteLine(((BitSet)set1 + (BitSet)set2));
            }
            else if (set1 is MultiSet)
            {
                Console.WriteLine(((MultiSet)set1 + (MultiSet)set2));
            }
            Console.WriteLine("Пересечение множеств:");
            if (set1 is SimpleSet)
            {
                Console.WriteLine(((SimpleSet)set1 * (SimpleSet)set2));
            }
            else if (set1 is BitSet)
            {
                Console.WriteLine(((BitSet)set1 * (BitSet)set2));
            }
            else if (set1 is MultiSet)
            {
                Console.WriteLine(((MultiSet)set1 * (MultiSet)set2));
            }
        }