22 lines
454 B
C++
Raw Normal View History

2024-03-07 13:27:19 -06:00
#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;
}
}
}