STL-related
This commit is contained in:
45
STL/STL-Set/set.cpp
Normal file
45
STL/STL-Set/set.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#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
|
||||
*/
|
Reference in New Issue
Block a user