DilyaraL

Untitled

Dec 15th, 2021
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. int finger_search(int* v, int len, int val) {
  2. int rad = 1;
  3. int l, r;
  4. int new_rad;
  5. while (true) {
  6. new_rad = min(rad * 2, len - 1);
  7. if (v[new_rad] >= val || new_rad == len - 1) {
  8. l = rad;
  9. r = new_rad;
  10. break;
  11. }
  12. rad = new_rad;
  13. }
  14. int fib_res = fib_search(&v[l], r - l + 1, val);
  15. if (fib_res == -1)
  16. return -1;
  17. else
  18. return l + fib_res;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment