public void Prepend(T value) { if (head == null) { head = new LinkListNode <T> { Value = value }; return; } var temp = new LinkListNode <T> { Value = value, Next = head }; head = temp; }
public void Add(T value) { var newEl = new LinkListNode <T> { Value = value }; var temp = head; if (temp == null) { head = newEl; return; } while (temp.Next != null) { temp = temp.Next; } temp.Next = newEl; }
public void AddAfter(LinkListNode <T> node, LinkListNode <T> newNode) { if (newNode.List != null || (node?.List ?? this) != this) { return; } if (First == null || Last == null) { First = Last = newNode; } else if (node == null) { newNode.Next = First; First.Previous = newNode; First = newNode; } else { if (node.Next is LinkListNode <T> nextNode) { nextNode.Previous = newNode; newNode.Next = nextNode; } else { Last = newNode; } newNode.Previous = node; node.Next = newNode; } newNode.List = this; Count++; }
public void AddLast(LinkListNode <T> node) => AddAfter(Last, node);
public void AddFirst(LinkListNode <T> node) => AddBefore(First, node);
public void AddBefore(LinkListNode <T> node, LinkListNode <T> newNode) => AddAfter(node?.Previous, newNode);
private void ClearNode(LinkListNode <T> node) { node.Previous = node.Next = null; node.List = null; }
public LinkList() { head = null; }
private LinkList(LinkListNode <T> head) { this.head = head; }
private void Deconstruct(out LinkListNode <T> head, out LinkList <T> tail) { head = this.head; tail = Tail; }