C++ STL
The STL provides ready-made containers, iterators and algorithms.
| Container | Description | Key operations |
|---|---|---|
| vector | Dynamic array | push_back, pop_back, [ ], size |
| list | Doubly linked list | push_front, push_back |
| stack / queue | LIFO / FIFO adapters | push, pop, top / front |
| priority_queue | Max-heap by default | push, pop, top |
| set / map | Sorted unique keys (red-black tree) | insert, find, erase |
| unordered_map | Hash table | O(1) average lookup |
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main() {
vector<int> v = {5, 3, 8, 1, 9};
sort(v.begin(), v.end());
for (int x : v) cout << x << " ";
cout << endl;
map<string, int> marks;
marks["Ravi"] = 76;
marks["Asha"] = 88;
for (auto &[name, m] : marks) cout << name << ": " << m << endl; // sorted by key
cout << "Max: " << *max_element(v.begin(), v.end()) << endl;
}
1 3 5 8 9
Asha: 88
Ravi: 76
Max: 9
Track your progress through the C++ course