Help rahul search

not passing all the test cases
#include
using namespace std;
int search(int a[],int s,int e,int ele){
if(s<=e)
{
int m=(s+e)/2;
if(a[m]==ele)
{
return m;
}
if(a[s]<=a[m])
{
if(ele==a[s]&&ele<a[m])
{
search(a,s,m-1,ele);
}
else
{
search(a,m+1,e,ele);
}
}
if(a[e]>a[m])
{
if(ele>=a[m]&&ele<=e)
{
search(a,m+1,e,ele);
}
else
{
search(a,s,m-1,ele);
}
}
}

	else
        return -1;
}

int main() {

int n,a[100000];
cin>>n;
int s=0;
int e=n-1;
int ele;
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
cin>>ele;
int c = search(a,s,e,ele);
cout<<c;

return 0;

}

Paste your code on ide.codingblocks.com and save it, and please then send the link of the code.
Approach:

  1. Find middle point mid = (l + h)/2
  2. If key is present at middle point, return mid.
  3. Else If arr[l…mid] is sorted
    a) If key to be searched lies in range from arr[l] to arr[mid], search in arr[l…mid].
    b) Else ssearch in arr[mid+1…h]
  4. Else (arr[mid+1…h] must be sorted)
    a) If key to be searched lies in range from arr[mid+1] to arr[h], search in arr[mid+1…h].
    b) Else search in arr[l…mid]

my codeblock ide does not work well…i hav already sent u my code please check

@ayu2321 ohh ok,so you are not returning the search and only calling it. The returned value only gets transferred to the previous function call and not to the main(). To fix this, where ever you are calling search(), just return it. So that value gets transferred back to main() as well.