(一) STL:
(A)#include <iostream> #include <algorithm> using namespace std;
1) void sort( iterator start, iterator end );
void sort( iterator start, iterator end, StrictWeakOrdering cmp );
cmp函数的参数类型只能和sort中排序的类型相同。
sort_heap 和sort 的使用方法相同。
void sort_heap( iterator start, iterator end );
void sort_heap( iterator start, iterator end, StrictWeakOrdering cmp );
2) a: bool binary_search( iterator start, iterator end, const TYPE& val ); bool binary_search( iterator start, iterator end, const TYPE& val, Comp f ); val表示的是要查找的值。
If val is found, binary_search() returns true, otherwise false
b:InputIterator find ( InputIterator first, InputIterator last, const T& value );
the usage would be:
cout<<find(a,a+20,5)-a<<endl;
or using the vector.
3) iterator partition( iterator start, iterator end, Predicate p );
通过p将元素分为两个部分。
iterator stable_partition( iterator start, iterator end, Predicate p );
不改变元素的顺序。
4) reverse(start,end) which can be used by combined with the <for_each(start,end,action)>like:
reverse(a,a+20);for_each(a,a+20,act); void act(int i){cout<<i<<” “;}cout<<endl;
5) remove(start , end, ele); remove the ele in the container.start to container.end. and the function return the last position of the container after remove the ele.
6) replace(start,end,old,new) using the new element to replace the old element in the range of [start,end]
7) rotate(start,mid,end) chang the range of [start,mid] with [mid,end] and the usage of it is the same of rp.
8) swap_ranges(arr1.start,arr1.end,arr2) this function change the range of arr1[start,end] with arr2.
9) transform(arr1.start,arr1.end,arr2,act) this function is cast the effect of act on the range of arry1 from start to end, and store the new element in the array2. Note that we need to initialize the array2 with enough space in order to store the element before recall transform
10) unique(arr.start,arr.end) this function will remove any sequential element in the array. And it will return iterator(if using vector) or int* ( you can check the usage in the program present below)
(二) numeric:
(A) #include <numeric> #include <iostream> using namespace std;
1) accumulate(start,end,init) init means the initial sum. By default the operation is sum, while the user can define other operation by define a function Like:
a) int myFunction(int x, int y){ return x+2*y;}
b) accumulate(start,end,init,myFunction);
2) numeric also include other standard function like:
adjacent_difference, inner_product, partial_sum which I need to acknowledge.