Update MP2
This commit is contained in:
parent
f3217d0614
commit
00e479a3a1
Binary file not shown.
@ -0,0 +1,21 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int binarySearch(std::vector arr, int numToSearchFor) {
|
||||||
|
std::sort(arr);
|
||||||
|
int first = 0;
|
||||||
|
int last = arr.size() - 1;
|
||||||
|
int position = INT_MIN;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
while (!found && first <= last) {
|
||||||
|
middle = (first + last) / 2;
|
||||||
|
if (arr[middle] == numToSearchFor) {
|
||||||
|
found = true;
|
||||||
|
position = middle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user