Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 12 / binarySearch.cpp
diff options
context:
space:
mode:
Commit30eb3cf6792a937909ea0583a0383806309e587f (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2022-01-05 18:20:19 +0200
Committer
 GitHub <noreply@github.com>
2022-01-05 18:20:19 +0200
Filesb3e6dda51a5f7163794b43cdadc45f3d2b0f8cd8 /Sem. 12/binarySearch.cpp
Introduction_to_programming_FMI-30eb3cf6792a937909ea0583a0383806309e587f.tar
Introduction_to_programming_FMI-30eb3cf6792a937909ea0583a0383806309e587f.tar.gz
Introduction_to_programming_FMI-30eb3cf6792a937909ea0583a0383806309e587f.zip
Parent9b65f562490fc3e39b730a0d95ff3f5e6bcccabd (diff)
Create binarySearch.cpp
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()
+{
+}