it = v.begin();
it += 6;
Is "it += 6;" done in O(n) or constant time ?
Can anyone help out?
i think its constant, just move address
So it's constant for std vector but for std list (that no random access is available) it'll be O(n) I think. Because the compiler says no operator '+=' is overloaded.
as i know += from C++17
Which book is it
Would be interesting to know if they give you any guarantees on complexity, but likely they won't
guarantees on the complexity of arithmetic operations on iterators?
You can see here that the operation on a random access I iterators is not O(1) while others iterators are O(n) https://en.cppreference.com/w/cpp/iterator/distance
Обсуждают сегодня