From 1ad74b0211ea1f5aa69f91bb8b29738bd47db504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Wed, 29 Oct 2014 15:01:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90adjacent=5Ffind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Algorithm.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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; + } }