mirror of
https://github.com/TheAlgorithms/C
synced 2025-02-13 20:14:32 +03:00
fix bug
This commit is contained in:
parent
f14320d137
commit
7f9d115226
@ -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 */
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user