The following function performs a non-recursive linear search of the given vector, returning a constant iterator to the element containing the given value. If the value does not exist, the "one-past-the-end" iterator is returned instead.
std::vector<int>::const_iterator find (int val, const std::vector<int>& v){
for (std::vector<int>::const_iterator it=v.begin(); it!=v.end(); ++it)
if (*it==val) return it;
return v.end();
}
Copyright © 2026 eLLeNow.com All Rights Reserved.