public void AddLast(T data) { var n = new DoublyLinkedListNode <T>(data); if (Tail != null) { Tail.Next = n; } n.Prev = Tail; Tail = n; if (Count == 0) { Head = Tail; } Count++; }
public virtual void AddFirst(T data) { var n = new DoublyLinkedListNode <T>(data) { Next = Head }; if (Head != null) { Head.Prev = n; } Head = n; if (Count == 0) { Tail = Head; } Count++; }
public virtual void AddBefore(DoublyLinkedListNode <T> node, T data) { if (node == null) { return; } if (node == Head) { AddFirst(data); return; } var newNode = new DoublyLinkedListNode <T>(data); node.Prev.Next = newNode; newNode.Next = node; newNode.Prev = node.Prev; node.Prev = newNode; Count++; }
public DoublyLinkedListNode(T data) { Data = data; Next = null; Prev = null; }
public DoublyLinkedList() { Count = 0; Head = null; Tail = null; }
public void Clear() { Count = 0; Tail = Head = null; }