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


bool binarySearch(const int* arr, unsigned size, int el)
{
	if (size == 0)
		return false;

	unsigned mid = size / 2;

	if (arr[mid] == el)
		return true;

	if (arr[mid] > el)
		return binarySearch(arr, mid, el);
	return binarySearch(arr + mid + 1, size - mid - 1, el);
}

int main()
{
}