Advertisement
CaminhoneiroHell

bs

Oct 18th, 2021
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. //template<class T> // overloaded operator < is used;
  2. //int binarySearch(const T arr[], int arrSize, const T& key) {
  3. //    int lo = 0, mid, hi = arrSize - 1;
  4. //    while (lo <= hi) {
  5. //        mid = (lo + hi) / 2;
  6. //        if (key < arr[mid])
  7. //            hi = mid - 1;
  8. //        else if (arr[mid] < key)
  9. //            lo = mid + 1;
  10. //        else return mid; // success: return the index of
  11. //    } // the cell occupied by key;
  12. //    return -1; // failure: key is not in the array;
  13. //}
  14. //
  15. //int main()
  16. //{
  17. //    //int arr[] = {2,3,4,5,6,7,7,8,8,9,3,45,23,23};
  18. //    //const auto result = binarySearch(arr, std::distance(std::begin(arr), std::end(arr)), 23);
  19. //    //std::cout << "Binary search result: \n" << result;
  20. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement