Learn C++ STL

Lesson 2 of 9 · array and deque: Fixed Size, and Growing at Both Ends

Module 4 · array and deque: Fixed Size, and Growing at Both Ends

Every array and deque Operation, One by One, With Its Cost

Free with an accountReading

Bob needs a list of numbers in reverse. In Module 2 he inserted each one at v.begin() of a vector, and 100,000 of them took about a third of a second. Now he writes the same line on a deque, d.insert(d.begin(), x), and it finishes in well under a millisecond. Same call, same count, about eight hundred times faster. "Is the deque cheating?" he asks. No: the cost of each call depends on the container, and this lesson writes that cost under every operation.

Checking what this lesson needs for you…

What is inside Every array and deque Operation, One by One, With Its Cost

  1. array: making one, and the braces that zero it
  2. array: operator[] and at
  3. array: front and back
  4. array: size and empty
  5. array: fill
  6. array: swap
  7. array: == and <
  8. array: data, begin and endIntermediate
  9. array: std::get<i>Intermediate
  10. deque: four ways to make one
  11. deque: push_back and push_front
  12. deque: pop_back and pop_front
  13. deque: operator[] and at
  14. deque: front, back, size and empty
  15. deque: insert and erase in the middle
  16. deque: clear and resize
  17. deque: shrink_to_fitIntermediate
  18. What a deque does not have
  19. Every cost in two tables, and Bob's measurement