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