/// <inheritdoc /> public bool MoveNext() { if (iCurrent.Next == null) { return(false); } iCurrent = iCurrent.Next; return(true); }
/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary> public LinearListEnumerator(LinearList <TItem> linearList) { iLinearList = linearList; // Must not be NULL iCurrent = new LinearListItem(default(TItem)) { Next = linearList._head }; }
/// <summary> /// Sorts the item of the collection using the given <paramref name="comparison"/> /// in ascending order. /// </summary> /// <param name="comparison">Comparison</param> private void SortInternal(Comparison <TItem> comparison) { // Note, the sort may be faster, if we use a 'sort by insert' (binary) approach LinearListItem currentRef = _head; // Iterate until the end while (currentRef != null) { // Current sublist head LinearListItem subListHead = currentRef; // Reference to current sublist minimum item LinearListItem minSublistItem = subListHead; TItem minItem = minSublistItem.Item; // Sublist iterator LinearListItem sublistCursor = subListHead; while (sublistCursor != null) { TItem sublistCursorItem = sublistCursor.Item; // If the current sublist cursor item is lower, we have a new minimum item bool isLower = comparison(sublistCursorItem, minItem) < 0; if (isLower) { minSublistItem = sublistCursor; minItem = sublistCursorItem; } // Move on sublistCursor = sublistCursor.Next; } // Now we have the lowest item, so we can swap it if (minSublistItem != subListHead) // Swap only if we have a real change { TItem buffer = subListHead.Item; subListHead.Item = minSublistItem.Item; minSublistItem.Item = buffer; } // Move on currentRef = currentRef.Next; } }
/// <inheritdoc /> public virtual bool Remove(TItem item) { if (item == null) { return(false); } LinearListItem precedingItem = null; LinearListItem current = _head; while (current != null) { TItem currentItem = current.Item; if (!Equals(currentItem, item)) { precedingItem = current; current = current.Next; continue; } // We matched the head if (current == _head) { _head = current.Next; } // We matched the tail if (current == _tail) { _tail = precedingItem; } // We matched any item in sequence if (precedingItem != null) { precedingItem.Next = current.Next; } Count--; return(true); } return(false); }
/// <inheritdoc /> public virtual void Add(TItem item) { if (item == null) { return; } if (_head == null) { _head = new LinearListItem(item); _tail = _head; } else { LinearListItem oldTail = _tail; _tail = new LinearListItem(item); oldTail.Next = _tail; } Count++; }
/// <inheritdoc /> public virtual void Clear() { _head = null; _tail = null; Count = 0; }
/// <inheritdoc /> public void Reset() => iCurrent = iLinearList._head;