Skip to content

Instantly share code, notes, and snippets.

@YassineBajdou
Created June 4, 2018 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YassineBajdou/cfaefc017b97bf3cf785595d180ad8b2 to your computer and use it in GitHub Desktop.
Save YassineBajdou/cfaefc017b97bf3cf785595d180ad8b2 to your computer and use it in GitHub Desktop.
Binary Search
int binarySearch(int low,int high,int key)
{
while(low<=high)
{
int mid=(low+high)/2;
if(a[mid]<key)
{
low=mid+1;
}
else if(a[mid]>key)
{
high=mid-1;
}
else
{
return mid;
}
}
return -1; //key not found
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment