public ListEntry(int degree, int a) { Degree = degree; A = a; Next = null; }
public static ListEntry Addition(ListEntry pol_1, ListEntry pol_2) { if (pol_1 != null && pol_2 != null) { ListEntry beg = new ListEntry(); ListEntry list = beg; ListEntry beg1 = pol_1; ListEntry temp1 = pol_1; ListEntry temp2 = pol_2; int slag = 0; while (pol_1 != null) { slag = 0; while (temp1 != null) { if (pol_1.Degree == temp1.Degree) { slag += temp1.A; } temp1 = temp1.Next; } while (temp2 != null) { if (pol_1.Degree == temp2.Degree) { slag += temp2.A; } temp2 = temp2.Next; } if (slag != 0) { list.Next = new ListEntry(pol_1.Degree, slag); list = list.Next; } temp2 = pol_2; pol_1 = pol_1.Next; temp1 = beg1; } list = beg.Next; temp1 = beg.Next; int count = 0; while (list != null) //проверка на одинаковые слагаемые { while (temp1 != null) { if (list.A == temp1.A && list.Degree == temp1.Degree) { count++; if (count > 1) { list.Next = list.Next.Next; } } temp1 = temp1.Next; } list = list.Next; temp1 = beg.Next; count = 0; } return(beg.Next); } else { return(null); } }
public ListEntry() { Degree = 0; A = 0; Next = null; }