insertAfter method
- int index,
- T value
Inserts a new element directly after the specified logical index.
Implementation
void insertAfter(int index, T value) {
if (index < 0 || index >= _length) {
throw RangeError.index(index, this, 'Index out of bounds');
}
_ForwardListNode<T>? current = _head;
for (int i = 0; i < index; i++) {
current = current!.next;
}
current!.next = _ForwardListNode<T>(value, current.next);
_length++;
}