C++ STL

The STL provides ready-made containers, iterators and algorithms.

ContainerDescriptionKey operations
vectorDynamic arraypush_back, pop_back, [ ], size
listDoubly linked listpush_front, push_back
stack / queueLIFO / FIFO adapterspush, pop, top / front
priority_queueMax-heap by defaultpush, pop, top
set / mapSorted unique keys (red-black tree)insert, find, erase
unordered_mapHash tableO(1) average lookup
C++
#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