Implement the STL find routine that returns the iterator containing the first occurrence of x in the range that begins at start and extends up to but not including end. If x is not found, end is returned. This is a nonclass (global function) with signature
template <typename Iterator, typename Object>
iterator find( Iterator start, Iterator end, const Object & x );
Here is the completed code for this method. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks
//required template method
template <typename Iterator, typename Object>
Iterator find( Iterator start, Iterator end, const Object & x ){
//looping until start and end are same
while(start!=end){
//checking if value associated with start iterator is x
if(*start == x){
return start; //found, returning start
}
//else, advancing start to next position
start++;
}
return end; //not found
}
Get Answers For Free
Most questions answered within 1 hours.