Merge pull request #103 from koseokkyu/otherbinarysearch

correct compilation error and logic error at Otherbinarysearch in search folder
This commit is contained in:
Anup Kumar Panwar 2017-11-25 14:28:54 +05:30 committed by GitHub
commit 694bc20327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,15 +2,15 @@
#include <stdlib.h> #include <stdlib.h>
#define len 5 #define len 5
int binarySearch(int array[] , int len , int searchX)
{
int binarySearch(int array[], int leng, int searchX)
{
int pos = -1, right, left, i = 0; int pos = -1, right, left, i = 0;
left = 0; left = 0;
right = len - 1; right = leng - 1;
for(i = 0; i < len ; i++) for (i = 0; i < leng; i++)
{ {
pos = (left + right) / 2; pos = (left + right) / 2;
@ -19,10 +19,10 @@ int binarySearch(int array[] , int len , int searchX)
else else
{ {
if (array[pos] < searchX) if (array[pos] < searchX)
right = pos - 1; left = pos + 1;
else else
{ {
left = pos + 1 ; right = pos - 1;
} }
} }
} }