Created
August 31, 2012 13:11
-
-
Save murikadan/3552495 to your computer and use it in GitHub Desktop.
Iterative Binary Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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