打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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用于设定比较函数
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C++学习之路—— STL标准模板库概述
linux内核组件初始化体系 - 但行好事 莫问前程 - JavaEye技术网站
AVR 单片机与GCC 编程之存储器操作
02、常量引用
Python|快速掌握单双链表和树
C语言实现的list
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服