insert method
Inserts item
at index
.
Implementation
void insert(int index, T item) {
if (index == 0 && _length >= _array.length) {
// when something is inserted at index 0 and the list is full then
// the new value immediately gets removed => nothing changes
return;
}
for (var i = _length - 1; i >= index; i--) {
_array[_getCyclicIndex(i + 1)] = _array[_getCyclicIndex(i)];
}
_array[_getCyclicIndex(index)] = item;
if (_length + 1 > _array.length) {
_startIndex += 1;
} else {
_length++;
}
}