STL 通用算法
1,非可变序列算法:指不直接修改其所操作的容器内容的算法。
find : Locates the position of the first occurrence of an element in a range that has a
specified value.(查找序列中第一个出现的给定值的位置)。它的判断函数的形式是
find_if : 查找序列中第一个使给定的判断函数返回真的元素。find 和 find_if 具有
线性时间复杂度。
adjacent_find : Searches for two adjacent elements that are either equal or satisfy a
specified condition.(查找在序列中相邻且相等或者满足指定条件的两个元素)此算
法返回指向两个元素中第一个元素的迭代器。adjacent_find 具有线性时间复杂度。
count : Counts the number of elements in the range [First, Last +1) that match Value
and returns the number of matching elements.(计算[First,Last+1)区间内与 Value
相匹配的对象的数目并作为返回值返回(相匹配元素的个数))。它的一元判断
函数形式是 count_if : 满足给定条件的元素的个数。count 和 count_if 具有线性
时间复杂度。
for_each : Applies a specified function object to each element in a forward order
within a range and returns the function object.对序列中指定范围内的每个元素施
加由指定函数指定的操作。返回函数对象拷贝。for_each 具有线性时间复杂度。
mismatch : Compares two ranges element by element either for equality or
equivalent in a sense specified by a binary predicate and locates the first position
where a difference occurs.比较容器中两个区间的元素。返回位置。详见书 p63。
具有线性时间复杂度。
equal : Compares two ranges element by element either for equality or equivalence
in a sense specified by a binary predicate.比较容器中两个区间的元素。返回真或假。
详见书 p63。具有线性时间复杂度。
search : Searches for the first occurrence of a sequence within a target range whose
elements are equal to those in a given sequence of elements or whose elements are
equivalent in a sense specified by a binary predicate to the elements in the given
sequence. 给定两个迭代器区间,将后一个区间内的对象作为一个子序列,并在
前一个区间内查找出现该子序列的第 1 个位置。它是对字符串匹配函数的推广,
比如 C 的库函数 strstr。
2、可变序列算法:可以修改它们所操作的容器内容的算法。
copy : Assigns the values of elements from a source range to a destination range,
iterating through the source sequence of elements and assigning them new positions
评论0