/// <summary> /// 移除所有节点; /// </summary> public void Clear() { DoublyLinkedListNode <T> current = First; while (current != null) { DoublyLinkedListNode <T> temp = current; current = current.Next; temp.Invalidate(); } First = null; Last = null; Count = 0; }
/// <summary> /// 移除这个节点之前的所有节点; /// </summary> public void RemoveBeforNodes(DoublyLinkedListNode <T> node) { ValidateNode(node); DoublyLinkedListNode <T> current = node.Previous; while (current != null) { DoublyLinkedListNode <T> temp = current; current = current.Previous; temp.Invalidate(); Count--; } node.Previous = null; First = node; }
/// <summary> /// 移除这个节点之后的所有节点; /// </summary> public void RemoveAfterNodes(DoublyLinkedListNode <T> node) { ValidateNode(node); DoublyLinkedListNode <T> current = node.Next; while (current != null) { DoublyLinkedListNode <T> temp = current; current = current.Next; temp.Invalidate(); Count--; } node.Next = null; Last = node; }
private void InternalRemoveNode(DoublyLinkedListNode <T> node) { if (node.Next == null) { Last = node.Previous; } else { node.Next.Previous = node.Previous; } if (node.Previous == null) { First = node.Next; } else { node.Previous.Next = node.Next; } node.Invalidate(); Count--; version++; }