The Standard Template Library gives ready-made containers and algorithms.
vector<int> v = {3, 1, 2};
v.push_back(4); // add at end
sort(v.begin(), v.end()); // 1 2 3 4
cout << v.size(); // 4
for (int x : v) cout << x << " ";
map<string, int> age; // sorted by key
age["Rahim"] = 25;
age["Karim"] = 30;
for (auto &[name, a] : age)
cout << name << " " << a << endl;
if (age.count("Rahim")) cout << "found";
set<int> s = {5, 1, 5, 3}; // unique and sorted: 1 3 5
s.insert(2);
cout << s.count(5); // 1 = present
| Container | Lookup | Notes |
|---|---|---|
| vector | O(1) by index | Contiguous, push_back amortised O(1) |
| map / set | O(log n) | Red-black tree, keeps keys sorted |
| unordered_map / set | O(1) average | Hash table, no order |
| stack / queue | top/front O(1) | Adapters for LIFO / FIFO |
| priority_queue | top O(1), push O(log n) | Max-heap by default |