Skip to content

Commit 306645c

Browse files
authored
Merge pull request #41 from Shoaib19/Shoaib019
still working on binary search
2 parents abb6d8e + 33088ce commit 306645c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

searching_algos/binary_search.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
int binary_search(int arr[],int size, int key)
22
{
3-
int mid = size / 2;
4-
if(arr[mid] == key)
5-
return mid;
63
int low = 0;
74
int high = size - 1;
85

9-
while(arr[mid] != key)
6+
while(low <= high)
107
{
8+
mid = low + (high - low) / 2;
9+
// start from here
1110
if(key < arr[mid])
1211
{
1312
high = mid;

0 commit comments

Comments
 (0)