Exemple #1
0
        public void Clear <T>(DoubleLinkedList <T> @this)
        {
            DoubleLinkedListNode <T> current = @this.Head;

            while (current != null)
            {
                DoubleLinkedListNode <T> temp = current;
                current = current.Next;   // use Next the instead of "next", otherwise it will loop forever
                temp.Invalidate();
            }

            @this.Head  = null;
            @this.Count = 0;
            @this.Version++;
        }
Exemple #2
0
 public void InternalRemoveNode <T>(DoubleLinkedList <T> @this, DoubleLinkedListNode <T> node)
 {
     Debug.Assert(node.List == @this, "Deleting the node from another list!");
     Debug.Assert(@this.Head != null, "This method shouldn't be called on empty list!");
     if (node.Next == node)
     {
         Debug.Assert(@this.Count == 1 && @this.Head == node, "this should only be true for a list with only one node");
         @this.Head = null;
     }
     else
     {
         node.Next.Previous = node.Previous;
         node.Previous.Next = node.Next;
         if (@this.Head == node)
         {
             @this.Head = node.Next;
         }
     }
     node.Invalidate();
     @this.Count--;
     @this.Version++;
 }