15 lines
387 B
Org Mode
15 lines
387 B
Org Mode
|
|
#+ANKI_DECK: study_deck_02
|
||
|
|
* std::binary_search: check element exists :cpp:binary-search:algorithm:retrieval::recognition:
|
||
|
|
:PROPERTIES:
|
||
|
|
:END:
|
||
|
|
|
||
|
|
** Front
|
||
|
|
What does ~std::binary_search~ return, and what must the range be?
|
||
|
|
|
||
|
|
** Back
|
||
|
|
Returns ~bool~ (true if element found). The range must be *sorted*.
|
||
|
|
|
||
|
|
#+begin_src cpp
|
||
|
|
bool found = std::binary_search(vec.begin(), vec.end(), value);
|
||
|
|
#+end_src
|