Trong hướng dẫn này, ta thảo luận về multiset lower_bound() trong C++ STL.
Hàm lower_bound() trả về iterator trỏ đến phần tử đầu tiên không nhỏ hơn key cho trước, hoặc end() nếu không có.
Ví dụ
#include <bits/stdc++.h> using namespace std; int main(){ multiset<int> s; s.insert(1); s.insert(2); s.insert(2); s.insert(1); s.insert(4); cout << "The multiset elements are: "; for (auto it = s.begin(); it != s.end(); it++) cout << *it << " "; auto it = s.lower_bound(2); cout << "\nThe lower bound of key 2 is " << (*it) << endl; it = s.lower_bound(3); cout << "The lower bound of key 3 is " << (*it) << endl; it = s.lower_bound(7); cout << "The lower bound of key 7 is " << (*it) << endl; return 0; }Đầu ra
The multiset elements are: 1 1 2 2 4 The lower bound of key 2 is 2 The lower bound of key 3 is 4 The lower bound of key 7 is 5