Find Pivot in array

 avatar
user_6075971
plain_text
a year ago
653 B
0
Indexable
Never
#include <iostream>
using namespace std;
int pivot(int arr[], int n)
{
    int s = 0;
    int e = n - 1;
    int mid = (s + e) / 2;
    while (s < e)
    {
        if (arr[0] < arr[mid])
        {
            s = mid + 1;
        }
        else
        {
          e= mid;
        }
        mid = (s + e) / 2;
    }
    return e;
}

int main()
{
    int arr[100];
    int n;
    cout << "ENTER THE ARRAY SIZE--->";
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 0; i < n; i++)
    {
        cout << arr[i] << "  ";
    }
    cout<<endl;
   cout << "YOUR PIVOT IS--->" << pivot(arr, n);

    return 0;
}