From d04b3a46db049e4271c7d949b636f26deead4886 Mon Sep 17 00:00:00 2001 From: Shitiz45 <86548099+Shitiz45@users.noreply.github.com> Date: Sat, 8 Oct 2022 10:15:26 +0530 Subject: [PATCH] Add files via upload --- pivot_search.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 pivot_search.cpp diff --git a/pivot_search.cpp b/pivot_search.cpp new file mode 100644 index 00000000..ee8304f4 --- /dev/null +++ b/pivot_search.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; +int getpivot(int arr[],int n) +{ + int s=0; + int e=n-1; + int mid=s+(e-s)/2; + while(s=arr[0]) + { + s=mid+1; + } + else + { + e=mid; + } + mid=s+(e-s)/2; + } + return s; +} +int main() { + vector arr; + int n; + cout<<"Enter the size of the array : "; + cin>>n; + for(int i=0;i>arr[i]; + } + int key; + cout<<"Enter element to be searched : "; + cin>>key; + int pivot=getpivot(arr,6); + if(arr[pivot]>key) + int pos=binary_search(arr.begin(),arr+pivot,key); + else pos=binary_search(arr+pivot,arr.end()); + if(pos==-1) + { + cout<<"Element not found!"; + } + else + { + cout<<"Element found at index "<