public void Reverse() { if (count == 0) { throw new Exception("List is empty"); } var curNode = _head; DoubleHeadedNode <T> nextNode = null; DoubleHeadedNode <T> prevNode = null; while (curNode != null) { nextNode = curNode.Next; curNode.Next = prevNode; prevNode = curNode; curNode = nextNode; if (curNode != null) { curNode.Previous = prevNode; } } _tail = _head; _tail.Next = null; _head = prevNode; }
public void InsertAtEnd(T value) { if (_head == null) { _head = new DoubleHeadedNode <T>(value); _tail = _head; } else { var newNode = new DoubleHeadedNode <T>(value); _tail.Next = newNode; newNode.Previous = _tail; _tail = newNode; } count++; }
public void InsertAtFront(T value) { if (_head == null) { _head = new DoubleHeadedNode <T>(value); _tail = _head; } else { var newNode = new DoubleHeadedNode <T>(value); newNode.Next = _head; _head.Previous = newNode; _head = newNode; } count++; }
public void RemoveFromEnd() { if (count == 0) { throw new Exception("List is empty"); } if (count == 1) { _head = _tail = null; count--; return; } _tail = _tail.Previous; _tail.Next = null; count--; }
public void RemoveFromFront() { if (count == 0) { throw new Exception("List is empty"); } if (count == 1) { _head = _tail = null; count--; return; } _head = _head.Next; _head.Previous = null; count--; }
public DoubleHeadedNode(T value = default(T)) { Value = value; Next = null; Previous = null; }