Generic Programming and the STL笔记3--“会改变操作对象之内容”的算法
来源:互联网 发布:java商城项目经验 编辑:程序博客网 时间:2024/05/21 17:51
1.1 copy
template <class InputIterator, class OutputIterator>
OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result);
1.2 copy_backward
template <class BidirectionalIterator1, class BidirectionalIterator2>
BindirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result);
2 互换元素
2.1 swap
template <class Assignable>
void swap(Assignable &a, Assignable &b)
2.2 iter_swap
template <class ForwardIterator1, class ForwardIterator2>
inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b);
3 transform
template <class InputIterator, class OutputIterator, class UnaryFunction>
OutputIterator transform(InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op);
template <class InputIterator1, class InputIterator2,
class OutputIterator, class BinaryFunction>
OutputIterator transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, BinaryFunction op);
4 替换元素
4.1 replace
template <class ForwardIterator, class T>
void replace(ForwardIterator first, ForwardIterator last, const T &old_value, const T &new_value);
4.2 replace_if
template <class ForwardIterator, class Predicate, class T>
void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T &new_value);
4.3 replace_copy
template <class InputIterator, class OutputIterator, class T>
OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T &old_value, const T &new_value);
4.4 replace_copy_if
template <class InputIterator, class OutputIterator, class Predicate, class T>
OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T &new_value);
5 充填整个区间
5.1 fill
template <class ForwardIterator, class T>
void fill(ForwardIterator first, ForwardIterator last, const T &value);
5.2 fill_in
template <class OutputIterator, class Size, class T>
OutputIterator fill_n(OutputIterator first, Size n, const T &value);
5.3 generate
template <class ForwardIterator, class Generator>
void generate(ForwardIterator first, ForwardIterator last, Generator gen);
5.4 generate_n
template <class OutputIterator, class Size, class Generator>
OutputIterator generate_n(OutputIterator first, Size n, const Generator gen);
6 移除元素
6.1 remove
template <class ForwardIterator, class T>
ForwardIterator remove(ForwardIterator first, ForwardIterator last, const T &value);
并没有真正移除元素,只是把不符合的数排在最后面。STL算法都这样。
6.2 remove_if
template <class ForwardIterator, class Predicate>
ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
6.3 remove_copy
template <class InputIterator, class OutputIterator, class T>
OutputIterator remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T &value);
6.4 remove_copy_if
template <class InputIterator, class OutputIterator, class Predicate>
OutputIterator remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
可用于实现copy_if,not1(pred)。但C++11已包含该函数
6.5 unique
template <class ForwardIterator>
ForwardIterator unique(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class BinaryPredicate>
ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred);
只移除相邻重复的,因此用之前先排序
6.6 unique_copy
template <class InputIterator, class OutputIterator>
OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result);
template <class InputIterator, class OutputIterator, class BinaryPredicate>
OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate binary_pred);
7 排列算法
7.1 reverse
template <class BidirectionalIterator>
void reverse(BidirectionalIterator first, BidirectionalIterator last);
7.2 reverse_copy
template <class BidirectinalIterator, class OutputIterator>
OutputIterator reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
7.3 rotate
template <class ForwardIterator>
inline void rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
7.4 rotate_copy
template <class ForwardIterator, class OutputIterator>
OutputIterator rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
7.5 next_permutation
template <class BidirectionalIterator>
bool next_permutation(BidirectionalIterator first, BidirectionalIterator last);
template <class BidirectionalIterator, class StrictWeakOrdering>
bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, StrictweakOrdering comp);
返回字典排序。如果是最后一个返回FALSE,返回为TRUE。
7.6 prev_permutation
template <class BidirectionalIterator>
bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
template <class BidirectionalIterator, class StrictWeakOrdering>
bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last, StrictWeakOrdering comp);
8 分割
8.1 partition
template <class BidirectionalIterator, class Predicate>
BidirectionalIterator partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred);
8.2 stable_partition
template <class ForwardIterator, class Predicate>
ForwardIterator stable_partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred);
9 随机重排与抽样
9.1 random_shuffle
template <class RandomAccessIterator>
void random_shuffle(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class RandomNumberGenerator>
void random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator &rand);
9.2 random_sample
template <class InputIterator, class RandomAccessIterator>
RandomAccessIterator random_sample(InputIterator first, InputIterator last, RandomAccessIterator ofirst, RandomAccessIterator olast);
template <class InputIterator, class RandomAccessIterator, class RandomNumberGenerator>
RandomAccessIterator random_sample(InputIterator first, InputIterator last, RandomAccessIterator ofirst, RandomAccessIterator olast, RandomNumberGenerator &rand);
不会保持相对位置
9.3 random_sample_n
template <class ForwardIterator, class OutputIterator, class Distance>
OutputIterator random_sample_n(ForwardIterator first, ForwardIterator last, OutputIterator out, Distance n);
template <class ForwardIterator, class OutputIterator, class Distance, RandomNumberGenerator &rand>
OutputIterator random_sample_n(ForwardIterator first, ForwardIterator last, OutputIterator out, Distance n, RandomNumberGenerator &rand);
会保持相对位置
10 一般化之数值算法
10.1 accumulate
template <class InputIterator, Class T>
T accumulate(InputIterator first, InputIterator last, T init);
template <class InputIterator, Class T>
T accumulate(InputIterator first, InputIterator last, T init, BinaryFunction binary_op);
10.2 inner_product
template <class InputIterator1, class InputIterator2, class T>
T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
10.3 partial_sum
template <class InputIterator, class OutputIterator>
OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result);
template <class InputIterator, class OutputIterator, class BinaryFunction>
OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryFuction binary_op);
10.4 adjacent_difference
template <class InputIterator, class OutputIterator>
OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
template <class InputIterator, class OutputIterator, class BinaryFuction>
OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryFuction binary_op);
- Generic Programming and the STL笔记3--“会改变操作对象之内容”的算法
- Generic Programming and the STL笔记2--“不改变操作对象之内容”的算法
- Generic Programming and the STL笔记1
- STL学习笔记(二) 会改变操作对象内容的算法
- Generic Programming and the STL笔记4--排序和查找
- Generic Programming and the STL笔记5--Iterator Classes
- Generic Programming and the STL笔记6--Function Object Classes
- Generic Programming and the STL笔记7--容器类
- 《Generic Programming and the STL》读书笔记
- STL学习笔记(一)不改变操作对象内容的算法
- Chapter 9 Templates. Generic Programming. and STL
- 读书摘要─Generic Programming and STL
- 不会改变操作对象内容的STL算法(元素查找,序列查找,统计元素个数,比较区间,找最值)
- Templates and Generic Programming
- 16-Templates and Generic Programming
- LUA学习笔记2-Iterators and the Generic for
- Effective STL笔记(1)-Programming with the STL
- Key-Value Coding (KVC) and Generic Programming
- jQuery之$(document).ready()使用介绍
- LocationManager的用法
- Ubuntu网络配置
- Android Gallery 3张图无限循环 左右滑动都有效
- Java常见面试题(二)JAVA集合类
- Generic Programming and the STL笔记3--“会改变操作对象之内容”的算法
- Java算法之动态规划
- Java中用split分割字符串
- HTML5智能表单
- 矩阵的特征值和特征向量【转】
- HLSL效果框架-多光源效果
- kvm虚拟机管理
- 移动web前端小结
- 史上最完整的文件和目录操作类