/// <summary> /// Inserts a specified item dataItem at an index. /// </summary> /// <param name="dataItem">Data item.</param> /// <param name="index">Index.</param> public void InsertAt(T dataItem, int index) { // Handle scope of insertion. // Prepend? Append? Or Insert in the range? if (index == 0) { Prepend(dataItem); } else if (index == Count) { Append(dataItem); } else if (index > 0 && index < Count) { var currentNode = _firstNode; var newNode = new SLinkedListNode <T>(dataItem); for (int i = 1; i < index; ++i) { currentNode = currentNode.Next; } newNode.Next = currentNode.Next; currentNode.Next = newNode; // Increment the count _count++; } else { throw new IndexOutOfRangeException(); } }
public int CompareTo(SLinkedListNode <T> other) { if (other == null) { return(-1); } return(this.Data.CompareTo(other.Data)); }
/// <summary> /// Inserts the specified dataItem at the end of the list. /// </summary> /// <param name="dataItem">The data value to be inserted to the list.</param> public void Append(T dataItem) { SLinkedListNode <T> newNode = new SLinkedListNode <T>(dataItem); if (_firstNode == null) { _firstNode = _lastNode = newNode; } else { var currentNode = _lastNode; currentNode.Next = newNode; _lastNode = newNode; } // Increment the count. _count++; }
public void Dispose() { _current = null; _doublyLinkedList = null; }
public void Reset() { _current = _doublyLinkedList.Head; }
public bool MoveNext() { _current = _current.Next; return(this._current != null); }
public SLinkedListEnumerator(SLinkedList <T> list) { this._doublyLinkedList = list; this._current = list.Head; }