Website Summary Files Commits Branches @commit @diff @stats
path: root / Seminar01 / src / searching-algorithms / binary-search.cpp
diff options
context:
space:
mode:
Commitdd9a7bf0fdcc3a04fcfb18ba1613d91b46ef0833 (patch)
Author
 Stoycho Kyosev <skyosev@192.168.100.17>
2024-10-20 07:47:14 -0400
Committer
 Stoycho Kyosev <skyosev@192.168.100.17>
2024-10-20 07:47:14 -0400
Files0e517f48f127dc1cb5418dacc61e48959ad34eb4 /Seminar01/src/searching-algorithms/binary-search.cpp
Data-structures-and-algorithms-dd9a7bf0fdcc3a04fcfb18ba1613d91b46ef0833.tar
Data-structures-and-algorithms-dd9a7bf0fdcc3a04fcfb18ba1613d91b46ef0833.tar.gz
Data-structures-and-algorithms-dd9a7bf0fdcc3a04fcfb18ba1613d91b46ef0833.zip
Parent8b287b482452f58491a2e1514cb37aa27b05929a (diff)
Add Sem02
1 files changed, 15 insertions, 1 deletions
-rw-r--r--Seminar01/src/searching-algorithms/binary-search.cpp16
diff --git a/Seminar01/src/searching-algorithms/binary-search.cpp b/Seminar01/src/searching-algorithms/binary-search.cpp
index b5befb0..7404e0a 100644
--- a/Seminar01/src/searching-algorithms/binary-search.cpp
+++ b/Seminar01/src/searching-algorithms/binary-search.cpp
@@ -27,7 +27,21 @@ int binarySearch(const T* arr, size_t size, T elem)
return -1;
}
+constexpr unsigned EXAMPLE_SIZE = 7;
+
int main()
{
-
+ int example[EXAMPLE_SIZE] = { 1, 2, 4, 8, 16, 32, 64 };
+ int needle = 4;
+
+ int index = binarySearch(example, EXAMPLE_SIZE, needle);
+ if(index == -1)
+ {
+ std::cout << "Unable to find the element" << std::endl;
+ }
+ else
+ {
+ std::cout << "Element " << needle << " found at "
+ << index << " position: " << example[index] << std::endl;
+ }
} \ No newline at end of file