2021-10-20 08:18:22 +00:00
|
|
|
/* This header defines the function for binary search in a sorted array. */
|
|
|
|
#ifndef BINARY_SEARCH_H
|
|
|
|
#define BINARY_SEARCH_H
|
|
|
|
|
|
|
|
/* Constants. */
|
2021-10-20 09:48:34 +00:00
|
|
|
#define BINARY_SEARCH_COMPARISON_LARGER_THAN 1
|
2021-11-15 13:09:05 +00:00
|
|
|
#define BINARY_SEARCH_COMPARISON_EQUAL_TO 0
|
2021-10-20 09:48:34 +00:00
|
|
|
#define BINARY_SEARCH_COMPARISON_LESS_THAN -1
|
|
|
|
#define BINARY_SEARCH_INDEX_NOT_FOUND -1
|
2021-10-20 08:18:22 +00:00
|
|
|
|
|
|
|
/* Function definitions. */
|
|
|
|
int binary_search(void* array, void* value, int (*comparison_function)(const void*, const void*), const int length, size_t size);
|
2021-10-20 09:48:34 +00:00
|
|
|
|
2021-10-20 08:18:22 +00:00
|
|
|
#endif /* BINARY_SEARCH_H */
|