STL — Standard Template Library
Mulțimi (set)
set<T> stochează elemente unice, automat sortate. Implementat ca arbore roșu-negru — operații O(log n).
#include <set>
using namespace std;
set<int> s;
s.insert(3); s.insert(1); s.insert(4);
s.insert(1); s.insert(5); // dublicatul 1 e ignorat
for (int x : s) cout << x << " ";
// 1 3 4 5 (sortat, fără duplicate)
cout << s.count(3) << endl; // 1 (există)
cout << s.count(7) << endl; // 0 (nu există)
s.erase(3); // elimină 3lower_bound și upper_bound
auto it = s.lower_bound(3); // iterator la primul element >= 3
auto it2 = s.upper_bound(3); // iterator la primul element > 3