int SearchInRotatedSortedArray(int array[], int low, int high, int target)
{
while(low <= high)
{
int mid = (low + high) / 2;
if (target < array[mid])
if (array[mid] < array[high])
high = mid - 1;
else
if(target < array[low])
low = mid + 1;
else
high = mid - 1;
else if(array[mid] < target)
if (array[low] < array[mid])
low = mid + 1;
else
if (array[high] < target)
high = mid - 1;
else
low = mid + 1;
else
return mid;
}
return -1;
}
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
int a[] = { 7, 11, 13, 17, 2, 3, 5};
cout << SearchInRotatedSortedArray(a, 0, 6, 1);
return 0;
}