STL — Standard Template Library
Hărți (map)
map<K,V> stochează perechi cheie-valoare, sortate după cheie. Fiecare cheie e unică.
map.cpp
#include <map>
using namespace std;
map<string, int> note;
note["Ana"] = 9;
note["Ion"] = 7;
note["Maria"] = 10;
cout << note["Ana"] << endl; // 9
cout << note.size() << endl; // 3
// Parcurgere
for (auto& [cheie, val] : note) {
cout << cheie << ": " << val << endl;
}
// Ana: 9 Ion: 7 Maria: 10Verificare cheie existentă
if (note.count("Ana")) cout << "Ana exista" << endl;
if (note.find("Popa") == note.end()) cout << "Popa nu exista" << endl;unordered_map oferă operații O(1) mediu (hash table) vs O(log n) la map. Folosește unordered_map când nu ai nevoie de ordine.