Skip to content

Instantly share code, notes, and snippets.

@murikadan
Created August 31, 2012 13:11
Show Gist options
  • Save murikadan/3552495 to your computer and use it in GitHub Desktop.
Save murikadan/3552495 to your computer and use it in GitHub Desktop.
Iterative Binary Search
int binsearch(int *,int,int,int);
int binsearch(int *a,int low,int high,int key)
{
while(high>=low)
{
int mid=(low+high)/2;
if(a[mid]==key)
return 1;
else if(a[mid]>key)
high=mid-1;
else
low=mid+1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment