add the comparison

This commit is contained in:
Jidong Xiao
2025-02-11 13:44:29 -05:00
committed by JamesFlare1212
parent cd0e681f45
commit b26a3d31f7

View File

@@ -5,6 +5,18 @@
- Our own version of the STL list<T> class, named dslist, Implementing list iterators - Our own version of the STL list<T> class, named dslist, Implementing list iterators
- Common mistakes, STL List w/ iterators vs. “homemade” linked list with Node objects & pointers - Common mistakes, STL List w/ iterators vs. “homemade” linked list with Node objects & pointers
## 11.0 When to Use `std::list` vs. `std::vector`
| Use Case | Prefer `std::vector` | Prefer `std::list` |
|----------------------------------------------|----------------------|--------------------|
| **Frequent insertions/removals at arbitrary positions** | ❌ | ✅ |
| **Fast random access required** | ✅ | ❌ |
| **Memory efficiency is important** | ✅ | ❌ |
| **Iterators should remain valid** | ❌ | ✅ |
| **Heavy insertions/deletions at the end** | ✅ | ✅ (but `std::vector` is better) |
| **Cache locality and performance are important** | ✅ | ❌ |
| **Large number of elements (better memory utilization)** | ✅ | ❌ |
## 11.1 Basic Linked Lists Mechanisms: Common Mistakes ## 11.1 Basic Linked Lists Mechanisms: Common Mistakes
- Here is a summary of common mistakes. Read these carefully, and read them again when you have problem that - Here is a summary of common mistakes. Read these carefully, and read them again when you have problem that