Skip to content

Commit 452a35f

Browse files
authored
Merge pull request #39 from Shoaib19/Shoaib019
incomplete binary search
2 parents 4cf9008 + 11ca583 commit 452a35f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

searching_algos/binary_search.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
void binary_search(int arr[],int size, int key)
1+
int binary_search(int arr[],int size, int key)
22
{
3-
// code here
3+
int mid = size / 2;
4+
if(arr[mid] == key)
5+
return mid;
6+
while(mid > 0 && mid < size)
7+
{
8+
if(key < arr[mid])
9+
{
10+
mid = mid / 2;
11+
}
12+
else if(key > arr[mid])
13+
{
14+
15+
}
16+
}
417
}

0 commit comments

Comments
 (0)