diff --git a/search.py b/search.py index c3f128c..0728297 100644 --- a/search.py +++ b/search.py @@ -42,5 +42,14 @@ def binary(data: List[Any], target: Any, comparator: Callable[[Any, Any], int]) - positive if a > b Returns the index of the found element, or -1 if not found. """ - pass - + high = len(data) - 1 + low = 0 + while low < high: + mid = (low + high) // 2 + if data[mid] == target: + return mid + if target > data[mid]: + low = mid + 1 + else: + high = mid - 1 + return -1