From 30eb3cf6792a937909ea0583a0383806309e587f Mon Sep 17 00:00:00 2001 From: Angel Dimitriev Date: Wed, 5 Jan 2022 18:20:19 +0200 Subject: Create binarySearch.cpp --- Sem. 12/binarySearch.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Sem. 12/binarySearch.cpp (limited to 'Sem. 12/binarySearch.cpp') diff --git a/Sem. 12/binarySearch.cpp b/Sem. 12/binarySearch.cpp new file mode 100644 index 0000000..589928a --- /dev/null +++ b/Sem. 12/binarySearch.cpp @@ -0,0 +1,21 @@ +#include + + +bool binarySearch(const int* arr, unsigned size, int el) +{ + if (size == 0) + return false; + + unsigned mid = size / 2; + + if (arr[mid] == el) + return true; + + if (arr[mid] > el) + return binarySearch(arr, mid, el); + return binarySearch(arr + mid + 1, size - mid - 1, el); +} + +int main() +{ +} -- cgit v1.3.1-23-gd82d