完成find_if和find_if_not

This commit is contained in:
邹晓航
2014-10-19 17:40:11 +08:00
parent f8f2233088
commit c6bb642098

View File

@@ -225,6 +225,26 @@ namespace TinySTL{
}
return first;
}
//********** [find_if] *************************
//********* [Algorithm Complexity: O(N)] ****************
template <class InputIterator, class UnaryPredicate>
InputIterator find_if(InputIterator first, InputIterator last, UnaryPredicate pred){
for (; first != last; ++first){
if (pred(*first))
break;
}
return first;
}
//********** [find_if_not] *************************
//********* [Algorithm Complexity: O(N)] ****************
template <class InputIterator, class UnaryPredicate>
InputIterator find_if_not(InputIterator first, InputIterator last, UnaryPredicate pred){
for (; first != last; ++first){
if (!pred(*first))
break;
}
return first;
}
}