daily pastebin goal
78%
SHARE
TWEET

Untitled

a guest Jan 16th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. bool binary_search_rec(int A[], int elem, int first, int last)
  3. {
  4.     if (first > last) return false;
  5.     int middle = (first + last) / 2;
  6.     if (elem == A[middle]) return true;
  7.     else if (elem < A[middle]) return binary_search_rec(A, elem, first, middle - 1);
  8.     else return binary_search_rec(A, elem, middle + 1, last);
  9. }
  10.  
  11. int main()
  12. {
  13.     int A[] = { 1,2, 3, 4, 5, 6 };
  14.     int x = 0;
  15.     if (binary_search_rec(A, x, 0, 5) == true) std::cout << "Is there";
  16.     else std::cout << "It is not!";
  17. }
RAW Paste Data
Top