Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned long binsearch(unsigned long long int nel, int (*less)(unsigned long i,unsigned long j))
- {
- unsigned long long int low = 0, high = nel-1, mid;
- while ( low <= high)
- {
- mid = low/2+high/2;
- if (less(high-1,high)&&less(high+1,high))
- return high;
- if (less(low-1,low)&&less(low+1,low))
- return low;
- if (less(mid-1,mid) && less(mid+1,mid))
- return mid;
- if(less(mid-1,mid))
- low = mid + 1;
- else
- if (less(mid+1,mid))
- high = mid - 1;
- else
- low=mid +1;
- }
- return nel;
- }
- unsigned long peak(unsigned long nel,
- int (*less)(unsigned long i, unsigned long j))
- {
- return binsearch(nel,less);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement