Skip to content

Instantly share code, notes, and snippets.

@Pr3d4dor
Last active August 29, 2015 14:24
Show Gist options
  • Save Pr3d4dor/2370897ec7d94a6d90a3 to your computer and use it in GitHub Desktop.
Save Pr3d4dor/2370897ec7d94a6d90a3 to your computer and use it in GitHub Desktop.
//Binary search function in c
int binarySearch(int *vet,int n,int x){
//The vector needs to be ordered for the binary search work properly, you can use any sorting method.
bubbleSort(vet,n);
while (ini<=end){
middle=(ini+end)/2;
if (vet[middle]==x)
return 1;
if (vet[middle]<x)
ini=middle+1;
else
end=middle-1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment