4 ms·
Agreed. But I can't think of any data structure that would offer you contiguous, order-preserving storage and O(1) insertions/deletions of arbitrary elements.
by georgecmu 16y ago
Agreed. But I can't think of any data structure that would offer you contiguous, order-preserving storage and O(1) insertions/deletions of arbitrary elements.
- jemfinch 16y agoThere are actually implementations of deque which can store elements contiguously: imagine a vector where the "first element" is placed in the middle of the vector, and push_{front,back} reallocate whenever either end is reached. It wastes more memory than the typical deque implementation, but the elements are contiguous.
- georgecmu 16y agoYou still don't get O(1) insertions/deletions of arbitrary elements with this implementation. Insertions and deletions at either end are O(1), but inserting/deleting in the middle is costly.