完成count
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#ifndef _ALGORITHM_H_
|
||||
#define _ALGORITHM_H_
|
||||
|
||||
#include "Allocator.h"
|
||||
#include "Functional.h"
|
||||
#include "Iterator.h"
|
||||
#include "TypeTraits.h"
|
||||
|
||||
#include <cstring>
|
||||
@@ -319,6 +321,18 @@ namespace TinySTL{
|
||||
}
|
||||
return first;
|
||||
}
|
||||
//********** [count] ******************************
|
||||
//********* [Algorithm Complexity: O(N)] ****************
|
||||
template <class InputIterator, class T>
|
||||
typename iterator_traits<InputIterator>::difference_type
|
||||
count(InputIterator first, InputIterator last, const T& val){
|
||||
typename iterator_traits<InputIterator>::difference_type n = 0;
|
||||
for (; first != last; ++first){
|
||||
if (*first == val)
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user