算法
|
用法 |
說明 |
copy
|
OutIt copy(InIt first,InIt last,OutIt x);
|
將[first,last)之間的元素復制到x指定的位置
|
copy_backward
|
BidIt2 copy_backward(BidIt1 first,BidIt1
last,BidIt2 x);
|
將[first,last)之間的元素復制到x指定位置的前面
|
fill
|
void fill(FwdIt first,FwdIt last,const T& x);
|
將[first,last)之間的部分用元素x填充
|
fill_n
|
void fill_n(OutIt first, Size n,const T& x);
|
從first開始向容器中填充n個元素x
|
generate
|
void generate(FwdIt first,FwdIt last, Gen g);
|
調用函數g()填充[first,last)之間的元素
|
generate_n
|
void generate_n(OutIt first,size n, Gen g);
|
調用函數g()填充從first開始的n個元素
|
remove
|
FwdIt remove(FwdIt first,FwdIt last,const T& val);
|
從[first,last)中刪除元素val,返回新區間中最后一個元素后的位置
|
remove_if
|
FwdIt remove_if(FwdIt first,FwdIt last, Pred pr);
|
從[first,last)中刪除所有能使函數pr返回true的元素,返回新區間最后一個元素后的位置
|
remove_copy
|
OutIt remove_copy(InIt first,InIt last,OutIt x,const T& val);
|
從[first,last)中刪除元素val,并把其余的元素復制到x開始的區間中,返回被拷貝的最后一個元素的位置
|
remover_copy_if
|
OutIt remove_copy_if(InIt first,InIt last,OutIt x,Pred pr);
|
從[first,last)中刪除所有能使函數pr返回true的元素,并把其余元素復制到x開始的空間,返回被拷貝最后一個元素的位置
|
replace
|
void replace(FwdIt first,FwdIt last,const T& vold,const T& vnew);
|
用vnew替換[first,last)中所有值為vold的元素
|
replace_if
|
void replace_if(FwdIt first,FwdIt last,Pred pr,const T& val);
|
用val替換[first,last)中所有能使函數pr返回true的元素
|
replace_copy
|
OutIt replace_copy(InIt first,InIt last,OutIt x,const T& vold,const
T& vnew);
|
把[first,last)中的所有元素復制到以x開始的空間中,如果拷貝的元素中存在值為vold的元素,則以vnew替換,返回拷貝到目標容器的最后一個元素的后一個位置
|
replace_copy_if
|
OutIt replace_copy_if(InIt first,InIt last,OutIt x,Pred pr,const T& val);
|
把[first,last)中的所有元素復制到以x開始的空間中,如果拷貝的元素中存在能夠使函數pr返回true的元素,則以vnew替換,返回拷貝到目標容器的最后一個元素的后一個位置
|
swap
|
void swap(Container &c1,Container &c2);
|
交換容器c1與c2的元素
|
iter_swap
|
void iter_swap(FwdIt1 x,FwdIt2 y);
|
交換迭代器x,y所指元素的值
|
swap_ranges
|
FwdIt2 swap_ranges(FwdIt1 first,FwdIt1 last,FwdIt2
x);
|
用起始于x的連續元素交換區間[first,last)的所有元素,返回第二個區間的最后一個元素的下一個位置
|
sort
|
void sort(RanIt first, RanIt last);
void sort(RanIt first, RanIt last, Pred pr);
|
將區間[first,last)中的元素按升序排序,第二種形式pr用于設定比較函數
|
merge
|
OutIt merge(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2,OutIt
x);
OutIt merge(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2,OutIt x, Pred
pr);
|
合并兩個有序區間[first1,last1)和[first2,last2),并將合并后的元素存儲到x開始的容器里,第二種形式pr(elem1,elem2)指定比較規則
|
inplace_merge
|
void inplace_merge(BidIt first, BidIt middle, BidIt last);
void inplace_merge(BidIt first, BidIt middle, BidIt last, Pred pr);
|
合并區間[first,middle)和[middle,last),并將合并后的元素存儲到first開始的區間,第二種形式pr(elem1,elem2)指定比較規則
|
reverse
|
void reverse(BidIt first, BidIt last);
|
將區間[first,last)的元素順序倒置
|
reverse_copy
|
OutIt reverse_copy(BidIt first, BidIt last,OutIt x);
|
將區間[first,last)的元素拷貝到x開始的區間,導致拷貝的元素順序,源區間沒有被修改,返回拷貝到目標區間的最后一個元素的下一個位置
|
rotate
|
void rotate(FwdIt first,FwdIt middle,FwdIt last);
|
交換區間[first,middle)和[middle,last)的元素位置
|
rotate_copy
|
OutIt rotate_copy(FwdIt first,FwdIt middle,FwdIt last,OutIt
x);
|
將區間[first,last)的元素拷貝到x開始的容器中,拷貝時交換[first,middle)和[middle,last)的位置,源區間不發生修改,返回拷貝到目標區間的最后一個元素的下一位
|
random_shuffle
|
void random_shuffle(RanIt first, RanIt last);
void random_shuffle(RanIt first, RanIt last, Fun& f);
|
對區間[first,last)上的元素進行隨機排序,f用于指定排序函數
|
transform
|
OutIt transform(InIt first,InIt last,OutIt x, Unop uop);
|
對區間[first,last)上的所有元素執行uop(elem)操作,結果放到以x開始的區間內,返回拷貝到目標端的最后一個元素的下一位
|
transform
|
OutIt transform(InIt1 first1,InIt1 last1,InIt2 first2,OutIt x, Binop
bop);
|
對區間[first1,last1)和以first2開始的區間的元素執行二元運算bop(elem1,elem2),結果放到以x開始的區間內,返回拷貝到目標端的最后一個元素的下一位
|
set_itersection
|
OutIt set_intersection(InIt1 first1,InIt1 last1,InIt2 first2,InIt2
last2,OutIt x);
OutIt set_intersection(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2,OutIt x, Pred pr);
|
求兩個區間[first1,last1),[first2,last2)的交集,存儲到x開始的容器里,源區間元素沒有被修改,pr用于指定操作函數,返回拷貝到目標區間的最后一個元素的下一個位置
|
set_union
|
OutIt set_union(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2,OutIt x);
OutIt set_union(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2,OutIt x,
Pred pr);
|
求兩個區間[first1,last1),[first2,last2)的并集,存儲到x開始的容器里,源區間元素沒有修改,pr用于指定操作函數,返回拷貝到目標區間的最后一個元素的下一位
|
set_difference
|
OutIt set_difference(InIt1 first1,InIt1 last1,InIt2 first2,InIt2
last2,OutIt x);
OutIt set_difference(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2,OutIt
x, Pred pr);
|
求兩個集合[first1,last1),[first2,last2)的差集,存儲到x開始的容器里,源區間元素沒有被修改,pr用于指定操作函數,返回拷貝到目標區間的最后一個元素的下一個位置
|
set_symmetric_
difference
|
OutIt set_symmetric_difference(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2,OutIt x);
OutIt set_symmetric_difference(InIt1 first1,InIt1 last1,InIt2 first2,InIt2
last2,OutIt x, Pred pr);
|
求集合[first1,last1),[first2,last2)的對稱差(即(A-B)+(B-A)),存儲到x開始的容器里,源區間元素沒有被修改,pr用于指定操作函數,返回拷貝到目標區間最后一個元素的下一個位置
|