Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. unsigned long peak(unsigned long nel, int (*less)(unsigned long i, unsigned long j)){
  2. unsigned long left = 0, right = nel-1, x, ans;
  3. while (left<right){
  4. x = left + (right-left)/2;
  5. if (less(x+1, x)) right = x;
  6. else left = x+1;
  7. }
  8. if(less(right, left)) ans = left;
  9. else ans = right;
  10. return ans;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement