29

The Standard Template Library gives ready-made containers and algorithms.

vector (dynamic array) C++ 5 lines
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 (key → value) C++ 6 lines
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 (unique, sorted) C++ 3 lines
set<int> s = {5, 1, 5, 3};  // unique and sorted: 1 3 5
s.insert(2);
cout << s.count(5);         // 1 = present
ContainerLookupNotes
vectorO(1) by indexContiguous, push_back amortised O(1)
map / setO(log n)Red-black tree, keeps keys sorted
unordered_map / setO(1) averageHash table, no order
stack / queuetop/front O(1)Adapters for LIFO / FIFO
priority_queuetop O(1), push O(log n)Max-heap by default