Created
July 9, 2018 08:04
-
-
Save ZiKT1229/9b525f107e160ac6b21ebfd1e5ffa065 to your computer and use it in GitHub Desktop.
BinarySearchExample
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
void binarySearch(int array[], int aim) | |
{ | |
int left=0, right=array_size-1, mid, ans; | |
while (left<=right) | |
{ | |
mid=(left+right)/2; | |
if (array[mid]<aim) | |
left=mid+1; | |
else if (array[mid]>aim) | |
right=mid-1; | |
else | |
{ | |
ans=array[mid]; | |
break; | |
} | |
} | |
cout<<ans<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment