Esempio n. 1
0
 /*
  * Metoda koja mnozi polinom i monom.
  */
 public void Pomnozi(Monom m)
 {
     for (int i = 0; i < poly.Count; i++)
     {
         poly[i].Coef  *= m.Coef;
         poly[i].Power += m.Power;
     }
 }
Esempio n. 2
0
        /*
         * Metoda za dodavanje monoma u polinom.
         * Ova metoda postuje navedena pravila za redjanje monoma u polinomu.
         */
        public void Dodaj(Monom m)
        {
            if (poly.Count == 0)
            {
                poly.Add(m);
                isNull = false;
                return;
            }
            int left = 0, right = poly.Count, border = (left + right) / 2;

            while (left <= right)
            {
                border = (left + right) / 2;
                if (border == poly.Count)
                {
                    poly.Add(m);
                    return;
                }
                if (poly[border].Power == m.Power && poly[border].Coef == -m.Coef)
                {
                    poly.RemoveAt(border);
                    return;
                }
                if (poly[border].Power == m.Power && m.Coef == 0)
                {
                    throw new System.Exception("Monom ne zadovoljava pravila!");
                }
                if (poly[border].Power < m.Power)
                {
                    left = border + 1;
                }
                else if (poly[border].Power > m.Power)
                {
                    right = border - 1;
                }
                else
                {
                    throw new System.Exception("Monom ne zadovoljava pravila!");
                }
            }
            if (poly[border].Power < m.Power)
            {
                poly.Insert(border + 1, m);
            }
            else if (poly[border].Power > m.Power)
            {
                poly.Insert(border, m);
            }
            else
            {
                throw new System.Exception("Monom ne zadovoljava pravila!");
            }
        }