public DoublePolynomList(List<int> values)
 {
     int count = 0;
     while ((count < values.Count) && (values[count] == 0))
         count++;
     if (count < values.Count)
     {
         int power = values.Count - count - 1;
         DoublePolynomNode _First = new DoublePolynomNode(values[count], power);
         _First.Prev = Head;
         DoublePolynomNode pos = _First;
         for (int i = count + 1; i < values.Count; i++)
         {
             power--;
             if (values[i] != 0)
             {
                 pos.Next = new DoublePolynomNode(values[i], power);
                 pos.Next.Prev = pos;
                 pos = pos.Next;
             }
         }
         pos.Next = Head;
         Head.Next = _First;
         Head.Prev = pos;
     }
 }
 public DoublePolynomList()
 {
     DoublePolynomNode Head = new DoublePolynomNode(-1,-1);
     Head.Next = Head;
     Head.Prev = Head;
 }
 public void AddToEnd(int value)
 {
     if (Head.Next != Head)
     {
         DoublePolynomNode node = Head.Prev;
         if (node.Power == 0)
             throw new Exception("Невозможно добавить элемент со степенью меньше 0");
         else
         {
             DoublePolynomNode insnode = new DoublePolynomNode(value, node.Power - 1);
             insnode.Next = Head;
             Head.Prev = insnode;
             node.Next = insnode;
             insnode.Prev = node;
         }
     }
 }
 public void Insert(IPolynomNode inode, int value)
 {
     DoublePolynomNode node = inode as DoublePolynomNode;
     if (node.Power != 0)
     {
         if (node.Next.Power == node.Power - 1)
             throw new Exception("Нет свободной степени для вставки");
         else
         {
             DoublePolynomNode insnode = new DoublePolynomNode(value, node.Power - 1);
             insnode.Next = node.Next;
             node.Next.Prev = insnode;
             node.Next = insnode;
             insnode.Prev = node;
         }
     }
 }
 public void AddToBegin(int value)
 {
     int power = 0;
     if (Head.Next != Head)
         power = Head.Next.Power + 1;
     DoublePolynomNode node = new DoublePolynomNode(value, power);
     node.Next = Head.Next;
     node.Prev = Head;
     Head.Next = node;
     if (Head.Next != Head)
         Head.Next.Prev = node;
 }