Пример #1
0
 public void RemoveFirst()
 {
     if (Count == 0)
     {
         Console.WriteLine("No elements to remove");
     }
     else
     {
         Count--;
         Head = Head.Next;
         if (Count == 0)
         {
             Tail = null;
         }
         else
         {
             Head.Prev = null;
         }
     }
 }
Пример #2
0
        public void AddToFirst(DoublyLinkedListNode <T> node)
        {
            var tempNode = Head;

            Head      = node;
            Head.Next = tempNode;
            Count++;
            if (Count == 1)
            {
                Tail = Head;
            }
            else
            {
                /// to resolve the case when this is the first node
                // Before: Head -------> 5 <-> 7 -> null
                // After:  Head -> 3 <-> 5 <-> 7 -> null
                // temp.Previous was null, now Head
                tempNode.Prev = Head;
            }
        }