kennen:lib:binary_search
Inhaltsverzeichnis
binary_search()
#include
<algorithm>
bool binary_search (For first, For last, T wert) bool binary_search (For first, For last, T wert, Binary comp) bool ranges::binary_search (Range r, T wert, Binary comp = {}, Proj proj = {}) bool ranges::binary_search (For first, For last, T wert, Binary comp = {}, Proj proj = {})
Prüft, ob wert
(als Projektion) in der aufsteigend geordneten Folge [first,last) enthalten ist.
Parameter
first | Anfang des Bereiches |
last | Ende des Bereiches |
wert | gesuchter Wert |
comp | Sortierkriterium (Vorgabe = less ) |
proj | einstelliger Funktor (Vorgabe = std::identity ) |
Ergebnis
Rückgabewert: true
, wenn wert
gefunden wurde
bzw. wenn es einen Iterator i
im Bereich [first,last) gibt, für den gilt:
comp(proj(*i), value) == false && comp(value, proj(*i)) == false
Siehe auch
Beispiel
- binary_search.cpp
#include <algorithm> #include <iostream> int main() { double arr[] = { 1, 2, 3, 4, 5 }; std::cout << std::binary_search(arr, arr+5, 2) << '\n'; }
kennen/lib/binary_search.txt · Zuletzt geändert: 2020-06-15 14:09 von 127.0.0.1