Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 12 / binarySearch.cpp
diff options
context:
space:
mode:
1 files changed, 21 insertions, 0 deletions
-rw-r--r--Sem. 12/binarySearch.cpp21
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 <iostream>
+
+
+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()
+{
+}