STL搜索算法小结

cout << "----------------非修改序列算法----------------------------" << endl;cout << "----------------查找搜索算法----------------------------" << endl;vector myVector{ 5,6,9,8,8,3 };auto iterBegin = myVector.begin();auto iterEnd = myVector.end();//查找不小于8的元素auto iterResult = find_if_not(iterBegin, iterEnd, [](int i) {return i < 8; });if (iterResult != iterEnd){cout << "First element not < 8 is " << *iterResult << endl;}//查找小于8的元素iterResult = find_if(iterBegin, iterEnd,[](int i) {return i < 8; });if(iterResult != iterEnd){cout << "First element < 8 is " << *iterResult << endl;}//查找最大元素iterResult = max_element(iterBegin, iterEnd);if (iterResult != iterEnd){cout << "the maxinum element is " << *iterResult << endl;}//查找最小元素iterResult = min_element(iterBegin, iterEnd);if (iterResult != iterEnd){cout << "the mixinum element is " << *iterResult << endl;}//查找连续相同的元素iterResult = adjacent_find(iterBegin, iterEnd);if (iterResult != iterEnd){cout << "find two consecutive equal element with value " << *iterResult << endl;}//查找子序列中的第一个元素vector vecTemp{ 2,8 };iterResult = find_first_of(iterBegin, iterEnd, cbegin(vecTemp), cend(vecTemp));if (iterResult != iterEnd){cout << "found first one of 8 or 9 -> " << *iterResult << endl;}//匹配第一个序列元素vector sub{ 8,3 };iterResult = search(iterBegin, iterEnd, sub.cbegin(), sub.cend());if (iterResult != iterEnd){cout << "find subsequence {8,3} " << endl;}else{cout << "not find subsequence {8,3}" << endl;}//匹配最后一个子序列auto result = find_end(iterBegin, iterEnd, sub.cbegin(), sub.cend());if (iterResult == result){cout << "Only one subsequence is {8,3}" << endl;}//查找n个连续相同的数值iterResult = search_n(iterBegin, iterEnd, 2, 8);if (iterResult != iterEnd){cout << "find two consecutive 8s" << endl;}else{cout << "unable to find consecutive 8s" << endl;}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值