Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. C++ Course

Lesson 22 of 45 · C++

Lesson 29: List Container

Duration: 10 min

List Container\n\nstd::list implements a doubly‑linked list. It excels at frequent insertions and deletions anywhere in the sequence, with constant‑time complexity.\n\n---\n\n## Characteristics\n- Non‑contiguous memory layout – each node contains pointers to predecessor and successor.\n- No random access – operator[] is unavailable; you must traverse.\n- Efficient splice operation to transfer elements between lists without copying.\n\n---\n\n## Example: Using splice to merge two lists\ncpp\nstd::list<std::string> l1 = {\"one\", \"two\"};\nstd::list<std::string> l2 = {\"three\", \"four\"};\n// Move all elements from l2 to the end of l1 without copying\nl1.splice(l1.end(), l2);\nfor (const auto& s : l1) std::cout << s << ' ';\nstd::cout << '\\n';\n\n\nAfter splicing, l2 becomes empty, and l1 now contains four elements.\n\n> Tip: Use list::remove_if with a predicate lambda to erase elements matching a condition.\n\n---\n\n<Alert type="info">If you need stable iterators during insertion/erase, std::list is a good choice, though its cache performance is poorer than std::vector.

Previous: Lesson 28: Vector ContainerNext: Lesson 3: Hello World and Basic Syntax