diff --git a/Assignments/MP2_CalebFontenot_clion/.binarySearch.cpp.kate-swp b/Assignments/MP2_CalebFontenot_clion/.binarySearch.cpp.kate-swp deleted file mode 100644 index 837d0ff..0000000 Binary files a/Assignments/MP2_CalebFontenot_clion/.binarySearch.cpp.kate-swp and /dev/null differ diff --git a/Assignments/MP2_CalebFontenot_clion/binarySearch.cpp b/Assignments/MP2_CalebFontenot_clion/binarySearch.cpp index e69de29..a696be5 100644 --- a/Assignments/MP2_CalebFontenot_clion/binarySearch.cpp +++ b/Assignments/MP2_CalebFontenot_clion/binarySearch.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +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; + } + } +}