1. lower_bound()
用於在指定區域內查找大於等於目標值的第一個元素(實質是二分法查找)
auto it = lower_bound(f.begin(), f.end(), num);
2. upper_bound()
查找的是第一個大於目標值的元素
int *p = upper_bound(a, a + 5, 3);
3. equel_range()
用於在指定范圍內查找等於目標值的所有元素,前提是已排好序
pair<int*, int*> range = equal_range(a, a + 9, 4);
4. find()
用於在指定范圍內查找和目標元素值相等的第一個元素,找不到會到end()
std::vector<int>::iterator it; it = find(myvector.begin(), myvector.end(), 30); if (it != myvector.end()) cout << "查找成功:" << *it; else cout << "查找失敗"; return 0;
5. binary_search()
用於查找指定區域內是否包含某個目標元素,返回bool
bool hasElem = binary_search(a, a + 9, 4);