static void Main(string[] args) { var pol = new Polinom3(); pol.DoPolinom3("text.txt"); Console.Write("pol: "); Console.WriteLine(pol.ToString()); pol.Insert(6, 4, 6, 1); Console.Write("Insert: "); Console.WriteLine(pol.ToString()); Console.Write("Delete: "); pol.Delete(4, 7, 2); Console.WriteLine(pol.ToString()); Console.Write("Value: "); Console.WriteLine(pol.Value(2, 1, 1)); Console.Write("MinCoef: "); var array = pol.MinCoef(); for (int i = 0; i < 3; i++) { Console.Write($"{array[i]} "); } Console.WriteLine(); Console.Write("Derivate: "); pol.Derivate(2); Console.WriteLine(pol.ToString()); var pol2 = new Polinom3(); pol2.DoPolinom3("text1.txt"); Console.Write("pol2: "); Console.WriteLine(pol2.ToString()); Console.Write("AddTwoPolinoms: "); pol.AddTwoPolinoms(pol2); Console.WriteLine(pol.ToString()); }
public void AddTwoPolinoms(Polinom3 p) { var elem1 = list.First; var elem2 = p.list.First; var prev = new Element(); if (Compare(elem1, elem2) > 0) { prev = elem1; elem1 = elem1.Next; } else { prev = elem2; elem2 = elem2.Next; } list.First = prev; while (elem1 != null || elem2 != null) { if (elem1 != null && elem2 != null) { if (Compare(elem1, elem2) > 0) { prev.Next = elem1; prev = prev.Next; elem1 = elem1.Next; } else { prev.Next = elem2; prev = prev.Next; elem2 = elem2.Next; } } else { if (elem1 != null) { prev.Next = elem1; prev = prev.Next; elem1 = elem1.Next; } else { prev.Next = elem2; prev = prev.Next; elem2 = elem2.Next; } } } }