Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int BinarySearch(int* arr, int num, int KEY){
- int S = num / 2;
- while(1){
- if(KEY > arr[S] ) S = (S + num) / 2;
- else if(KEY < arr[S] ) S /= 2;
- else return S;
- }
- }
- /*
- int Search(int* arr, int number, int KEY){
- int i = 0;
- while(i < number){
- if(arr[i] == KEY) return i;
- i++;
- }
- return -1;
- }
- */
- int main(){
- int arr[10] = {1, 10, 24, 36, 47, 50, 55, 61, 73, 89};
- printf("%d", BinarySearch(arr, 10, 36) + 1 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement