I am trying to implement a method of binary search that uses vector::iterators as it's a main driver for recursive calls.
So far I have:
template<typename T, typename iter>
vector<int>::iterator binary_search(iter low, iter high, T key) {
if (high < low) return -1;
iter median = distance(low, high) / 2;
if (*median == key)
return median;
else if (*median > key)
return binary_search(low, median - 1, key);
return binary_search(median + 1 , high, key);
}
But I receive the compiler errors:
- 'binary_search': ambiguous call to overloaded function
- more than one instance of overloaded function "binary_search" matches the argument list
with the call
vector<int> nums = { 0,1,2,3,4,5,6,7,8,9 };
binary_search(nums.begin(), nums.end(), 1);
Besides that, if you happen to catch something else faulty, please let me know! Thanks in advance.