int search(int A[], int n, int target) {

```
if(!n)
return -1;
if(n==1)
return A[0]==target? 0:-1;
int middle=0,start=0, end=n-1;
while(start<end)
{
middle=(start+end)/2;
if(A[middle]==target)
return middle;
else if (A[start]<=A[middle])
{
if(target>=A[start] && target<A[middle])
end=middle-1;
else
start=middle+1;
}
else //if(A[start]>A[middle])
{
if( target>A[middle] && target<=A[end])
start=middle+1;
else
end=middle-1;
}
}
return -1;
}
```

how to fix it ?