Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- bool binary_search_rec(int A[], int elem, int first, int last)
- {
- if (first > last) return false;
- int middle = (first + last) / 2;
- if (elem == A[middle]) return true;
- else if (elem < A[middle]) return binary_search_rec(A, elem, first, middle - 1);
- else return binary_search_rec(A, elem, middle + 1, last);
- }
- int main()
- {
- int A[] = { 1,2, 3, 4, 5, 6 };
- int x = 0;
- if (binary_search_rec(A, x, 0, 5) == true) std::cout << "Is there";
- else std::cout << "It is not!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement