#include <iostream> using namespace std; int pivotSearch (int arr[],int n) { int start = 0; int end = n-1; int mid = start + (end-start)/2; while (start < end) { if (arr[mid] >= arr[0]) { start = mid + 1; } else { end = mid; } mid = start + (end-start)/2; } return end; } int main() { int arr[5] = {3,8,10,17,1}; int ans = pivotSearch(arr,5); cout << "the pivot is : "<< ans; return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter