diff --git a/TinySTL/Algorithm.h b/TinySTL/Algorithm.h index e43717a..af05fdc 100644 --- a/TinySTL/Algorithm.h +++ b/TinySTL/Algorithm.h @@ -1,7 +1,9 @@ #ifndef _ALGORITHM_H_ #define _ALGORITHM_H_ +#include "Allocator.h" #include "Functional.h" +#include "Iterator.h" #include "TypeTraits.h" #include @@ -319,6 +321,18 @@ namespace TinySTL{ } return first; } + //********** [count] ****************************** + //********* [Algorithm Complexity: O(N)] **************** + template + typename iterator_traits::difference_type + count(InputIterator first, InputIterator last, const T& val){ + typename iterator_traits::difference_type n = 0; + for (; first != last; ++first){ + if (*first == val) + ++n; + } + return n; + } }