Last active
August 29, 2015 14:24
-
-
Save Pr3d4dor/2370897ec7d94a6d90a3 to your computer and use it in GitHub Desktop.
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
//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