diff --git a/TinySTL/Algorithm.h b/TinySTL/Algorithm.h index 63b30ae..e43717a 100644 --- a/TinySTL/Algorithm.h +++ b/TinySTL/Algorithm.h @@ -1,6 +1,9 @@ #ifndef _ALGORITHM_H_ #define _ALGORITHM_H_ +#include "Functional.h" +#include "TypeTraits.h" + #include namespace TinySTL{ @@ -301,6 +304,21 @@ namespace TinySTL{ } return last1; } + //********** [adjacent_find] ****************************** + //********* [Algorithm Complexity: O(N)] **************** + template + ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last){ + return TinySTL::adjacent_find(first, last, + equal_to::value_type>()); + } + template + ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred){ + for (; first != last; ++first){ + if (first + 1 != last && pred(*(first), *(first + 1))) + break; + } + return first; + } }