ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อทำความเข้าใจ multiset lower_bound() ใน C++ STL
ฟังก์ชัน lower_bound() จะคืนค่าการมีอยู่แรกขององค์ประกอบในคอนเทนเนอร์ที่เทียบเท่ากับพารามิเตอร์ที่ให้มา มิฉะนั้นจะคืนค่าองค์ประกอบที่ใหญ่กว่านั้นทันที
ตัวอย่าง
#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 ";
cout << (*it) << endl;
it = s.lower_bound(3);
cout << "The lower bound of key 3 is ";
cout << (*it) << endl;
it = s.lower_bound(7);
cout << "The lower bound of key 7 is ";
cout << (*it) << endl;
return 0;
} ผลลัพธ์
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