Files
Data-Structure/STL/STL-Set/set.cpp
2025-08-12 23:00:31 +08:00

46 lines
916 B
C++

#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(){
auto cmp = [](auto a, auto b){
return a > b;
};
set<int> a;
set<int> b = {1, 5, 4, 3, 3, 2};
set<int, decltype(cmp)> c(cmp);
a.insert(1);a.insert(5);a.insert(3);a.insert(2);
c.insert(1);c.insert(5);c.insert(3);c.insert(2);
a.emplace(6);
for(auto x : a){
cout << x << " ";
}
cout << endl;
for(auto x : c){
cout << x << " ";
}
cout << endl;
cout << a.count(3) << endl;
a.erase(6);
for(auto it = a.begin(); it != a.end(); it++){
cout << *it << " ";
}
//From "Smaller" To "Bigger", To compare big, we need "func:cmp"
cout << endl;
cout << *(c.find(5))<< endl;
//lower_bound : >= val ; upper_bound : > val ;
cout << *(c.lower_bound(2)) << " " << *(c.upper_bound(2)) << endl;
cout << *(a.lower_bound(2)) << " " <<*(a.upper_bound(2)) << endl;
return 0;
}
/*
COUT
1 2 3 5 6
5 3 2 1
1
1 2 3 5
5
2 1
2 3
*/