Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 13 / task7.cpp
blob: c90cf32d7a8853a282df0c074c590f0faf4f5c1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

bool BinarySearch(const int* arr, int len, int searched)
{
	if (len == 0)
		return false;

	int midIndex = len / 2;

	if (arr[midIndex] == searched)
		return true;
	if (arr[midIndex] < searched)
		return BinarySearch(arr + midIndex + 1, len - midIndex - 1, searched);
	else
		return BinarySearch(arr, midIndex, searched);
}

int main()
{
	int arr[] = { 1, 2, 2, 6, 19, 55 };
	cout << BinarySearch(arr, 6, 19);
}