洗尘斋

三悬明镜垂鸿韵,九撩清泉洗尘心

常用链接

统计

最新评论

STL非修改算法

由于STL算法都是通过迭代器间接处理容器,下面定义istream_iteratorInIt,ostream_itreatorOutIt,forward_iteratorFwdIt,bidirectional_iterator BidIt,random_iterator RanIt

非修改算法:

算法 用法 说明
adjacent_find FwdIt adjacent_find(FwdIt first,FwdIt last);
FwdIt adjacent_find(FwdIt first,FwdIt last,Pred pr);
在[first,last)查找相同元素的首次出现或能使pr(elem,nextElem)为true的元素的位置 ,函数查找成功返回位置,失败返回last
binary_search bool binary_search(FwdIt first,FwdIt last,const T& val);
bool binary_search(FwdIt first,FwdIt last,const T& val,Pred pr);
在区间[first,last)中查找元素val,如果找到返回true,否则返回false,第二种形式pr用于设定查找准则
count size_t count(InIt first,InIt last,const T& val); 返回区间[first,last)上val出现的次数
count_if size_t count_if(InIt first,InIt last,Pred pr); 返回区间[first,last)上满足条件pr(elem)的元素个数
equal bool equal(InIt1 first,InIt1 last,InIt2 x);
bool equal(InIt1 first,InIt1 last,InIt2 x,Pred pr);
判断[first,last)与x开始的区间的元素是否相等,pr用于指定判断函数
equal pair<FwdIt,FwdIt> equal_range(FwdIt first,FwdIt last,const T& val);
pair<FwdIt,FwdIt> equal_range(FwdIt first,FwdIt last,const T& val,Pred pr);
返回元素val第一次出现的位置和最后出现的位置的下一位组成的对,pr指定比较算法
lower_bound FwdIt lower_bound(FwdIt first,FwdIt last,const T& val);
FwdIt lower_bound(FwdIt first,FwdIt last,const T& val,Pred pr);
返回已排序序列[first,last)中val首次出现的位置,pr指定比较算法
upper_bound FwdIt upper_bound(FwdIt first,FwdIt last,const T& val);
FwdIt upper_bound(FwdIt first,FwdIt last,const T& val,Pred pr);
返回已排序序列[first,last)中val最后一次出现的下一个位置,pr指定比较算法
find InIt find(InIt first,InIt last,const T& val); 在[first,last)之间查找元素val,如果找到返回位置,找不到返回last
find_if InIt find_if(InIt first,InIt last, Pred pr); 在[first,last)之间查找能使函数pr返回true的元素,找到返回位置,否则返回last
find_end FwdIt1 find_end(FwdIt1 first1,FwdIt1 last1,FwdIt2 first2,FwdIt2 last2);
FwdIt1 find_end(FwdIt1 first1,FwdIt1 last1,FwdIt2 first2,FwdIt2 last2, Pred pr);
在[first1,last1)之间查找[first2,last2)最后出现的位置,如果找到返回位置,失败返回last1,第二个函数的pr函数用于比较两个容器的元素,在两个容器的元素相等时返回true
find_first_of FwdIt1 find_first_of(FwdIt1 first1,FwdIt1 last1,FwdIt2 first2,FwdIt2 last2);
FwdIt1 find_first_of(FwdIt1 first1,FwdIt1 last1,FwdIt2 first2,FwdIt2 last2, Pred pr);
在[first1,last1)之间查找第一次出现[first2,last2)中元素的位置,找到返回位置,失败返回last1,第二个函数pr用于比较两个容器的元素是否相等
for_each Fun for_each(InIt first,InIt last, Fun f); 对[first,last)上的所有元素执行函数f(elem),返回值常被忽略
includes bool includes(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2);
bool includes(InIt1 first1,InIt1 last1,InIt2 first2,InIt2 last2, Pred pr);
判断已排序序列[first1,last1)中是否包含区间已排序区间[first2,last2),pr指定元素的顺序
mismatch pair<InIt1,InIt2> mismatch(InIt1 first,InIt1 last,InIt2 x);
pair<InIt1,InIt2> mismatch(InIt1 first,InIt1 last,InIt2 x, Pred pr);
返回序列[first,last)与x开始的序列第一个不匹配的位置的两个迭代器组成的对
max const T& max(const T& x,const T& y);
const T& max(const T& x,const T& y, Pred pr);
返回x,y之间的较大者,pr(elem1,elem2)用于指定比较规则
max_element FwdIt max_element(FwdIt first,FwdIt last);
FwdIt max_element(FwdIt first,FwdIt last, Pred pr);
返回区间[first,last)上最大值的位置,pr(elem1,elem2)用于指定比较规则
min const T& min(const T& x,const T& y);
const T& min(const T& x,const T& y, Pred pr);
返回x,y之间的较小者,pr(elem1,elem2)用于指定比较规则
min_element FwdIt min_element(FwdIt first,FwdIt last);
FwdIt min_element(FwdIt first,FwdIt last, Pred pr);
返回区间[first,last)上的最小值的位置,pr(elem1,elem2)用于指定比较规则
search FwdIt1 search(FwdIt1 first1,FwdIt1 last1,FwdIt2 first2,FwdIt2 last2);
FwdIt1 search(FwdIt1 first1,FwdIt1 last1,FwdIt2 first2,FwdIt2 last2, Pred pr);
在[first1,last1)中查找子区间[first2,last2),如果找到返回在第一个区间中的位置,失败返回last1,第二种形式pr函数用于设定比较函数
search_n FwdIt search_n(FwdIt first,FwdIt last,Dist n,const T& val);
FwdIt search_n(FwdIt first,FwdIt last,Dist n,const T& val, Pred pr);
在[first,last)中查找连续n个val,如果找到返回在区间中的位置,失败返回last,第二种形式pr用于设定比较函数

posted on 2006-04-20 23:24 芥之舟 阅读(553) 评论(0)  编辑 收藏 引用 所属分类: STL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理