Learn C++ STL

Lesson 4 of 9 · list and forward_list: When Elements Move and Positions Must Not

Module 5 · list and forward_list: When Elements Move and Positions Must Not

When to Use list or forward_list, and Why the Answer Is Usually No

Free with an accountReading

Kenji keeps a price list sorted at all times. He reads that a list inserts in O(1), and a vector in O(n), so he moves his prices into a list. His program gets slower, about twenty times slower in the run below. Amara asks him one question: where did each new price go, and how did you find that place? This lesson is the answer, and for most programs it is "not in a list".

Checking what this lesson needs for you…

What is inside When to Use list or forward_list, and Why the Answer Is Usually No

  1. Six questions about your data
  2. The comparison chart
  3. The decision flowchart
  4. Kenji's prices: Stroustrup's experiment, small
  5. A table of iterators: Zara's bookmark bar
  6. Closing by a held position, measured
  7. forward_list: many short chains
  8. When the answer is no