|
C Fundamentals
Algorithms · data structures · cryptography · systems — pure C11, zero deps
|
Iterative + recursive binary search. More...
Go to the source code of this file.
Functions | |
| size_t | binary_search_ints (const int *arr, size_t n, int target) |
| size_t | binary_search_ints_recursive (const int *arr, size_t lo, size_t hi, int target) |
| size_t | binary_search_strings (const char *const *arr, size_t n, const char *target) |
Iterative + recursive binary search.
Note the lo + (hi - lo) / 2 midpoint computation — (lo + hi) / 2 would overflow on huge arrays. With size_t we'd need n > SIZE_MAX/2 to actually trip it, but the safer form is free.
Definition in file binary_search.c.
| size_t binary_search_ints | ( | const int * | arr, |
| size_t | n, | ||
| int | target | ||
| ) |
| size_t binary_search_ints_recursive | ( | const int * | arr, |
| size_t | lo, | ||
| size_t | hi, | ||
| int | target | ||
| ) |
Definition at line 46 of file binary_search.c.
References binary_search_ints_recursive(), and BSEARCH_NOT_FOUND.
Referenced by binary_search_ints_recursive().
| size_t binary_search_strings | ( | const char *const * | arr, |
| size_t | n, | ||
| const char * | target | ||
| ) |
Definition at line 29 of file binary_search.c.
References BSEARCH_NOT_FOUND.