示例#1
0
 public _Polynom(_Polynom value)
 {
     foreach (var item in value.listElements)
     {
         listElements.Add(item.Value.power, new Element(item.Value));
     }
 }
示例#2
0
        public static _Polynom operator -(_Polynom data1, _Polynom data2)
        {
            if (!ValidateForOperation(data1, data2))
            {
                throw new ArgumentNullException();
            }

            _Polynom result = new _Polynom(data1);

            foreach (var item in data2.listElements)
            {
                if (result.listElements[item.Key] != null)
                {
                    result.listElements[item.Key].coefficient -= item.Value.coefficient;

                    if (result.listElements[item.Key].coefficient == 0)
                    {
                        result.listElements.Remove(item.Key);
                    }
                }
                else
                {
                    result.Add(new Element(item.Value.coefficient * (-1), item.Value.power));
                }
            }

            return(result);
        }
示例#3
0
 private static bool ValidateForOperation(_Polynom data1, _Polynom data2)
 {
     if (data1 == null || data2 == null || data1.listElements == null || data2.listElements == null)
     {
         return(false);
     }
     return(true);
 }
示例#4
0
        static void Main(string[] args)
        {
            Dictionary <int, Element> le = new Dictionary <int, Element>();

            le.Add(1, new Element(1, 9));
            le.Add(2, new Element(2, 2));
            le.Add(4, new Element(4, 7));
            le.Add(7, new Element(77, 4));
            le.Add(9, new Element(2, 1));
            _Polynom p1 = new _Polynom(le);

            p1.ChangeCoefInElement(2, 20);
            p1.ChangePowerInElement(7, 22);
            Dictionary <int, Element> dict = new Dictionary <int, Element>();

            _Polynom p2 = new _Polynom(p1);
            _Polynom p3 = p1 * p2;

            Console.ReadKey();
        }
示例#5
0
        public static _Polynom operator *(_Polynom data1, _Polynom data2)
        {
            if (!ValidateForOperation(data1, data2))
            {
                throw new ArgumentNullException();
            }

            _Polynom result = new _Polynom();

            foreach (var item1 in data1.listElements)
            {
                foreach (var item2 in data2.listElements)
                {
                    int    newPower = item1.Value.power + item2.Value.power;
                    double newCoef  = item1.Value.coefficient * item2.Value.coefficient;

                    result.Add(newCoef, newPower);
                }
            }

            return(result);
        }