Skip to content

Instantly share code, notes, and snippets.

@ZiKT1229
Created July 9, 2018 08:04
Show Gist options
  • Save ZiKT1229/9b525f107e160ac6b21ebfd1e5ffa065 to your computer and use it in GitHub Desktop.
Save ZiKT1229/9b525f107e160ac6b21ebfd1e5ffa065 to your computer and use it in GitHub Desktop.
BinarySearchExample
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