Giao diện
Part 4: STL Containers Intermediate
Làm chủ C++ Standard Library — Containers là nền tảng của mọi chương trình C++ hiện đại
Tại sao học STL?
STL (Standard Template Library) là bộ công cụ sẵn có trong mọi C++ compiler. Thay vì tự viết linked list, hash table, hay sorting algorithm, bạn sử dụng những implementations đã được tối ưu qua hàng chục năm.
📌 HPN Standard
Rule: Luôn ưu tiên STL containers/algorithms trước khi tự viết. "Don't reinvent the wheel."
Module Structure
📘 Part 1: Core Containers
| Topic | Description |
|---|---|
| std::vector | Dynamic array — container phổ biến nhất |
| std::string | Text handling với string operations |
| std::map & unordered_map | Key-value storage |
| Performance Analysis | Big O của từng container |
| Iterators | Traversing containers |
| Modern Arrays | Stop using C-arrays! |
📙 Part 2: Algorithms & Lambdas
| Topic | Description |
|---|---|
| Algorithms Overview | <algorithm> và <numeric> headers |
| Lambda Expressions | Inline functions và closures |
| Sorting & Comparators | Custom sort rules |
| Searching | find, binary_search, bounds |
| Transform & Reduce | Functional operations |
| ⚡ Code Golf | STL power demonstrations |
The Big 3 Containers
┌─────────────────────────────────────────────────────────────────┐
│ THE BIG 3 CONTAINERS │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ │
│ │ std::vector │ Dynamic array │
│ │ ───────────── │ • Contiguous memory │
│ │ [1][2][3][4] │ • Fast random access O(1) │
│ │ │ • Cache-friendly │
│ └─────────────────┘ • Use 90% of the time │
│ │
│ ┌─────────────────┐ │
│ │ std::string │ Text container │
│ │ ───────────── │ • UTF-8 aware operations │
│ │ "Hello" │ • Concatenation, search, replace │
│ │ │ • Small String Optimization (SSO) │
│ └─────────────────┘ │
│ │
│ ┌─────────────────┐ │
│ │ std::map │ Sorted key-value │
│ │ ───────────── │ • O(log n) lookup │
│ │ {a:1, b:2} │ • Use unordered_map for O(1) │
│ │ │ • Iteration in sorted order │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘Prerequisites
📋 YÊU CẦU
- ✅ Pointers & References
- ✅ Range-based for loops
- ✅ const Best Practices
- ✅ Basic understanding of templates (sử dụng, không cần viết)
Learning Path
"Use std::vector by default. Use other containers only if you have a reason." — Bjarne Stroustrup