public void Add(DoublyLinkedListNode <T> node) { if (node == null) { throw new ArgumentNullException(); } if (IsEmpty()) { this.FirstNode = this.LastNode = node; } else { this.LastNode.Next = node; node.Prev = this.LastNode; this.LastNode = this.LastNode.Next; } this.Count++; }
public void Remove(DoublyLinkedListNode <T> node) { if (node == null || IsEmpty()) { throw new InvalidOperationException(); } if (this.FirstNode == node) { this.FirstNode = this.FirstNode.Next; this.FirstNode.Prev = this.FirstNode ?? null; } else if (this.LastNode == node) { this.LastNode = this.LastNode.Prev; this.LastNode.Next = this.LastNode ?? null; } else { node.Prev.Next = node.Next; node.Next.Prev = node.Prev; } this.Count--; }