Thursday, December 04, 2008

Find the start in the circular shifted array

A sorted array, with over a million elements in it, is rotated clockwise. Find out the index where the sorted list starts.



int find_index(int *a,int start,int end)
{
int mid = (start+end)/2;
if (a[start] < a[mid] < a[end])
return start;
else if(a[start] > a[mid])
return find_index(a, start, mid);
else if(a[mid] > a[end])
return find_index(a, mid, end);
}

No comments:

Post a Comment