47 lines
973 B
C++
47 lines
973 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);
|
||
//没有.at()和a[i],树结构,不能直接访问第i个,可以it++
|
||
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
|
||
*/
|