intmain(){ // Initialize a set. // Compare parameter is default to std::less<Key>. std::set<int> min_s; min_s.insert(1); min_s.insert(3); min_s.insert(2); min_s.insert(5); min_s.insert(4); min_s.insert(-1);
std::cout << "min value of set container is " << *min_s.begin() << std::endl; std::cout << "max value of set container is " << *min_s.rbegin() << std::endl;
// Compare parameter is default to std::greater<Key>. std::set<int, std::greater<int>> max_s; max_s.insert(1); max_s.insert(3); max_s.insert(2); max_s.insert(5); max_s.insert(4); max_s.insert(-1);
std::cout << "max value of set container is " << *max_s.begin() << std::endl; std::cout << "min value of set container is " << *max_s.rbegin() << std::endl;
std::cout << "max value of multiset container is " << *max_ms.begin() << std::endl; std::cout << "min value of multiset container is " << *max_ms.rbegin() << std::endl;
return0; }
输出结果如下
1 2 3 4 5 6
min value of set container is -1 max value of set container is 5 max value of set container is 5 min value of set container is -1 max value of multiset container is 5 min value of multiset container is -1