Lists are sequence containers that allow constant time insert and erase operations anywhere within the sequence, and iteration in both directions."
The main drawback of lists and forward_lists compared to these other sequence containers is that they lack direct access to the elements by their position
myList.emplace(it, 5, "Value"); // this should be very fast
O(1)) when computing the offset and we can jump directly to the desired element, as in
std::listto get (insert, delete, etc.) somewhere in the middle, we need this place to get to, along the way beating lower(higher) elements lying one after the other. It is quite slow (
O(n)). But the insertion itself will be cheap anywhere (
Find more questions by tags C++