From 5b7ebd5a9b0eeba9c95584271f016112aca82bb0 Mon Sep 17 00:00:00 2001 From: Marcos Hernanz Date: Wed, 7 Sep 2022 11:41:52 +0200 Subject: [PATCH] Small change to prevent overflow --- Searching/binary search/cpp/binarySearch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Searching/binary search/cpp/binarySearch.cpp b/Searching/binary search/cpp/binarySearch.cpp index 69904db8e..cbdaf261c 100644 --- a/Searching/binary search/cpp/binarySearch.cpp +++ b/Searching/binary search/cpp/binarySearch.cpp @@ -3,7 +3,7 @@ using namespace std; bool BinarySearch(int arr[], int n, int k){ int s=0;int e=n-1; while (s<=e){ - int mid=(s+e)/2; + int mid=s+(e-s)/2; if (arr[mid]==k) return true; if (arr[mid]