public void InsertLast(int data) { if (_head == null) { _head = new DoubleLinkedListNode(data); return; } var temp = _head; while (temp.Next != null) { temp = temp.Next; } temp.Next = new DoubleLinkedListNode(data, null, temp); }
public void Reverse() { var current = _head; DoubleLinkedListNode temp = null; while (current != null) { temp = current.Prev; current.Prev = current.Next; current.Next = temp; current = current.Prev; } if (temp != null) { _head = temp.Prev; } }
public void DeleteFromLast() { if (_head == null) { throw new NullReferenceException(); } if (_head.Next == null) { _head = null; return; } var temp = _head; while (temp.Next.Next != null) { temp = temp?.Next; } temp.Next = null; }
public DoublyLinkedList(DoubleLinkedListNode head = null) { _head = head; }