diff --git a/C++/标准库/2.1 顺序容器.md b/C++/标准库/2.1 顺序容器.md index 97f1ab9c..d5a83910 100644 --- a/C++/标准库/2.1 顺序容器.md +++ b/C++/标准库/2.1 顺序容器.md @@ -31,7 +31,7 @@ ![](2021-03-05-20-42-30.png) > 操作记忆 -> * back、front、push_back、push_front、pop_back、pop_front。是一组首尾相关的操作。 +> * back、front、push_back、push_front、pop_back、pop_front、emplace_front、emplace_back。是一组首尾相关的插入操作。 > * insert、at、erase。是一组随机的操作。 diff --git a/C++/标准库/4 算法.md b/C++/标准库/4 算法.md index 21d0a36d..ac9d45c8 100644 --- a/C++/标准库/4 算法.md +++ b/C++/标准库/4 算法.md @@ -29,24 +29,38 @@ | 3 | 排序算法Sorting/Partitions/Binary search/(对序列排序、合并、搜索算法操作。) | | 4 | 数值算法Merge/Heap/Min/max(对容器内容进行数值计算。) | -## 1.1 基础算法 -### 填充 +### 参数说明 + +|参数|说明| +|----|----| +beg|开始迭代器 +end|终止迭代器 +val|值 +func|操作函数 +n|整数 +comp|比较函数,返回true/false +binary|判断函数,返回true/false + +## 1.1 基础算法(遍历算法) + + +### 检查 +* 检查谓词是否对范围中所有、任一或无元素为 true | 函数 | 作用 | |---|---| -| fill(beg,end,val) | 将值val赋给[beg,end)范围内的所有元素。 | -| fill_n(beg,n,val) | 将值val赋给[beg,beg+n)范围内的所有元素。 | -| generate(beg,end,func) | 连续调用函数func填充[beg,end)范围内的所有元素。 | -| generate_n(beg,n,func) | 连续调用函数func填充[beg,beg+n)范围内的所有元素。 | +|all_of(beg,end,binary)|检查所有的元素是否满足binary| +|any_of(beg,end,binary)|检查任意的元素是否满足binary| +|none_of(beg,end,binary)|检查没有元素满足binary| -### 遍历、变换 +### 遍历变换 | 函数 | 作用 | |---|---| | for_each(beg,end,func) | 将[beg,end)范围内所有元素依次调用函数func,返回func。不修改序列中的元素。 | | transform(beg,end,res,unary) | 将[beg,end)范围内所有元素依次调用函数unary,结果放入res中。 | -| transform(beg2,end1,beg2,res,binary) | 将[beg,end)范围内所有元素与[beg2,beg2+end-beg)中所有元素依次调用函数unary,结果放入res中。 | +| transform(beg1,end1,beg2,res,binary) | 将[beg,end)范围内所有元素与[beg2,beg2+end-beg)中所有元素依次调用函数unary,结果放入res中。 | ### 最大最小 | 函数 | 作用 | @@ -59,6 +73,10 @@ | min(a,b,cmp) | 使用自定义比较操作cmp,返回两个元素中较小一个。 | | min_element(beg,end) | 返回一个ForwardIterator,指出[beg,end)中最小的元素。 | | min_element(beg,end,cmp) | 使用自定义比较操作cmp,返回一个ForwardIterator,指出[beg,end)中最小的元素。 | +|minmax(beg,end)|返回一个pair,包含最小最大值| +|minmax(beg,end,cmp)|自定义比较函数| +|minmax_element(beg,end)|返回一个pair,包含最大最小值的位置| +|minmax_element(beg,end,cmp)|自定义比较函数| ## 1.2 排序算法(12个) @@ -106,7 +124,7 @@ | count(beg,end,val) | 利用==操作符,对[beg,end)的元素与val进行比较,返回相等元素个数。 | | count_if(beg,end,pred) | 使用函数pred代替==操作符执行count()。 | -### 查找 +### 查找(查找某个值) | 函数 | 作用 | |---|---| @@ -119,7 +137,7 @@ | adjacent_find(beg,end) | 对[beg,end)的元素,查找一对相邻重复元素,找到则返回指向这对元素的第一个元素的ForwardIterator。否则返回end。 | | adjacent_find(beg,end,pred) | 使用函数pred代替==操作符执行adjacent_find()。 | -### 搜索 +### 搜索(搜索某个序列) | 函数 | 作用 | |---|---| @@ -141,7 +159,17 @@ | equal_range(beg,end,val) | 返回一对iterator,第一个表示lower_bound,第二个表示upper_bound。 | | equal_range(beg,end,val,comp) | 使用函数comp代替比较操作符执行lower_bound()。 | -## 1.4 删除和替换算法15个 +## 1.4 填充复制移除替换算法19个 + +### 填充 + + +| 函数 | 作用 | +|---|---| +| fill(beg,end,val) | 将值val赋给[beg,end)范围内的所有元素。 | +| fill_n(beg,n,val) | 将值val赋给[beg,beg+n)范围内的所有元素。 | +| generate(beg,end,func) | 连续调用函数func填充[beg,end)范围内的所有元素。 | +| generate_n(beg,n,func) | 连续调用函数func填充[beg,beg+n)范围内的所有元素。 | ### 复制 @@ -185,7 +213,9 @@ | swap_range(beg1,end1,beg2) | 将[beg1,end1)内的元素[beg2,beg2+beg1-end1)元素值进行交换。 | | iter_swap(it_a,it_b) | 交换两个ForwardIterator的值。 | -## 1.5 算数算法(4个) +## 1.5 算术算法(4个) + +`#inlcude` | 函数 | 作用 | |---|---| @@ -239,12 +269,14 @@ | 函数 | 作用 | |---|---| +|is_heap(beg,end[,comp]) | 检查给定范围是否为一个最大堆| +|is_heap_until(beg,end[,comp]) | 查找能成为最大堆的最大子范围| | make_heap(beg,end) | 把[beg,end)内的元素生成一个堆。 | | make_heap(beg,end,comp) | 将函数comp代替<操作符,执行make_heap()。 | -| pop_heap(beg,end) | 重新排序堆。它把first和last-1交换,然后重新生成一个堆。可使用容器的back来访问被"弹出"的元素或者使用pop_back进行真正的删除。并不真正把最大元素从堆中弹出。 | -| pop_heap(beg,end,comp) | 将函数comp代替<操作符,执行pop_heap()。 | | push_heap(beg,end) | 假设first到last-1是一个有效堆,要被加入到堆的元素存放在位置last-1,重新生成堆。在指向该函数前,必须先把元素插入容器后。 | | push_heap(beg,end,comp) | 将函数comp代替<操作符,执行push_heap()。 | +| pop_heap(beg,end) | 重新排序堆。它把first和last-1交换,然后重新生成一个堆。可使用容器的back来访问被"弹出"的元素或者使用pop_back进行真正的删除。并不真正把最大元素从堆中弹出。 | +| pop_heap(beg,end,comp) | 将函数comp代替<操作符,执行pop_heap()。 | | sort_heap(beg,end) | 对[beg,end)内的序列重新排序。 | | sort_heap(beg,end,comp) | 将函数comp代替<操作符,执行push_heap()。 |