From aedb6bca58b177245cf2cb2d0ee20929be097784 Mon Sep 17 00:00:00 2001 From: Kapliuk Date: Tue, 12 Nov 2024 11:46:07 +0000 Subject: [PATCH] Delete a2/binary_search.h --- a2/binary_search.h | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 a2/binary_search.h diff --git a/a2/binary_search.h b/a2/binary_search.h deleted file mode 100644 index 7589424..0000000 --- a/a2/binary_search.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef BINARY_SEARCH_H -#define BINARY_SEARCH_H - -#include -#include -#include - -const int *binary_search(int value, const int *arr, size_t length) { - if (length == 0) { - return NULL; - } - - size_t left = 0; - size_t right = length - 1; - - while (left <= right) { - size_t middle = left + (right - left) / 2; - - if (arr[middle] == value) { - return &arr[middle]; - } else if (arr[middle] > value) { - if (middle == 0) { - break; - } - right = middle - 1; - } else { - left = middle + 1; - } - } - return NULL; -} - -#endif \ No newline at end of file