#include
#include
/* Standard Binary Search function*/
//binarySearch(arr, 0,7)
int binarySearch(int arr[], int low, int high)
{
if(high >= low)
{
int mid = (low + high)/2; /*low + (high - low)/2;*/
if(arr[mid-1]
return arr[mid];
if(arr[mid-1]
else if(arr[mid-1]>arr[mid] && arr[mid]>arr[mid+1])
return binarySearch(arr, low, (mid -1));
}
/*Return -1 if element is not found*/
return -1;
}
/* Driver program to check above functions */
int main()
{
int arr[] = {3, 4, 5, 6,7,1, 2};
printf("Maximum Element in Array is %d", binarySearch(arr, 0,5));
getchar();
return 0;
}
Run Here https://ideone.com/JOzXP
No comments :
Post a Comment