Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
realDuYuanChao committed Aug 25, 2019
1 parent f14320d commit 7f9d115
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions searching/Other_Binary_Search.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ int binarySearch(int array[], int leng, int searchX)
left = 0;
right = leng - 1;

for (i = 0; i < leng; i++)
while(left <= right)
{
pos = (left + right) / 2;

if (array[pos] == searchX)
pos = left + (right - left) / 2;
if(array[pos] == searchX)
{
return pos;
}
else if(array[pos] > searchX)
{
right = pos - 1;
}
else
{
if (array[pos] < searchX)
left = pos + 1;
else
{
right = pos - 1;
}
left = pos + 1;
}
}



return -1; /* not found */
}


Expand Down

0 comments on commit 7f9d115

Please sign in to comment.