C++ STL 学习笔记

(一)   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)                 uniquearr.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.
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值