1) Write a function named problem1 that accepts two arguments to the beginning a
ID: 656502 • Letter: 1
Question
1) Write a function named problem1 that accepts two arguments to the beginning
and end iterators of a container. Return a std::pair whose first value is an
iterator to the smallest element in the range and whose second value is an
iterator to the largest element in the range. You can create a pair easily
with the std::make_pair function: std::make_pair(x, y) returns a pair with x
as the first elememnt and y as the second. This is a template function and
should work with any containers.
2) Write a function named problem2 that accepts two arguments: a two dimensional
vector of a template type and a value of the sample template type as is
stored in the 2D vector. Search for a value in the given two dimensional 2D
vector and return the x,y coordinate of an element with that value or return
std::make_pair(-1, -1) if the element is not present.
Explanation / Answer
template ForwardIterator lower_bound (ForwardIterator first, ForwardIterator last, const T& val) { ForwardIterator it; iterator_traits::difference_type count, step; count = distance(first,last); while (count>0) { it = first; step=count/2; advance (it,step); if (*itRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.