public virtual DLinkedList <T> GetRange(int index, int countOfElements) { DLinkedListNode <T> currentNode = null; DLinkedList <T> newList = new DLinkedList <T>(); if (Count == 0) { return(newList); } if (index < 0 || index > Count) { throw new IndexOutOfRangeException(); } if (index > (Count / 2)) { currentNode = this._lastNode; for (int i = (Count - 1); i > index; --i) { currentNode = currentNode.Previous; } } else { currentNode = this._firstNode; for (int i = 0; i < index; ++i) { currentNode = currentNode.Next; } } // Append the elements to the new list using the currentNode reference while (currentNode != null && newList.Count <= countOfElements) { newList.Append(currentNode.Data); currentNode = currentNode.Next; } return(newList); }
public void Dispose() { _current = null; _doublyLinkedList = null; }
public DLinkedListEnumerator(DLinkedList <T> list) { this._current = list.Head; this._doublyLinkedList = list; }