提交 2016eb67 编写于 作者: 邹晓航

完成count

上级 24ba5808
#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;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册