文章目录
一、set
template < class T, // set::key_type/value_type
class Compare = less<T>, // set::key_compare/value_compare
class Alloc = allocator<T> // set::allocator_type
> class set;
1、常用成员函数
2、案例
#include <iostream>
#include <set>
using namespace std;
set<int> s = {19, 22, 11};
int main() {
//cout << "max_size: " << s.max_size() << endl;
// ret: 4
//s.insert(100);
//cout << "size: " << s.size() << endl;
// ret: 5
//s.insert(s.begin(), 110);
//cout << "size: " << s.size() << endl;
// ret: 2
//s.erase(19);
//cout << "size: " << s.size() << endl;
// ret: 7 8
//set<int> s2 = {7, 8};
//s.swap(s2);
//for(auto& i:s) {
// cout << i << " ";
//}
//s.clear();
//for(auto& i:s) {
// cout << i << " ";
//}
// ret: 110 19 22 11 100
//s.emplace(100);
//s.emplace_hint(s.begin(), 110);
//for(auto& i:s) {
// cout << i << " ";
//}
// ret: 1 对象的比较
//auto mycomp = s.key_comp();
//cout << mycomp(1,2) << endl;
// ret:19
//auto it = s.find(19);
//if(it != s.end())
// cout << *it << endl;
// ret:find!!!
//if(s.count(19)!=0)
// cout << "find!!!" << endl;
//else
// cout << "no!!!" << endl;
// ret:19
//auto it = s.lower_bound(19);
//cout << *it << endl;
// ret:22
//auto it = s.upper_bound(19);
//cout << *it << endl;
// ret:
//auto it = s.equal_range(19);
//cout << "lower_bound:" << *it.first << endl;
//cout << "upper_bound:" << *it.second << endl;
return 0;
}