Skip to content

Instantly share code, notes, and snippets.

@64lines
Last active January 1, 2016 09:29
Show Gist options
  • Save 64lines/8125221 to your computer and use it in GitHub Desktop.
Save 64lines/8125221 to your computer and use it in GitHub Desktop.
int binarySearch(int vector[], int n, int data)
{
int center;
int inf = 0;
int sup = n - 1;
while(inf <= sup){
center = (sup + inf) / 2;
if(vector[centro] == data) {
return centro;
} else if (data < vector[centro] ) {
sup = center - 1;
} else {
inf = center + 1;
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment