C++ algorithm

#include <iostream>  
#include <Algorithm>
#include <string>
#include <vector>

using namespace std;



int main()
{
	//count
	vector<int> vec = {1,2,2,34,4,5,6,71,85,9};
	int num = count_if(vec.begin(), vec.end(), [](int x) {return x > 50; });
	//min  max
	auto it1 = max_element(vec.begin(),vec.end());
	auto it2 = max_element(vec.begin(), vec.end(), [](int x, int y) {return (x % 10) < (y % 10); });

	auto it2 = min_element(vec.begin(),vec.end());

	//数据无序
	auto it4 = find(vec.begin(),vec.end(),71);
	auto it5 = find_if(vec.begin(), vec.end(), [](int x) {return x > 50; });
	auto it6 = find_if_not(vec.begin(), vec.end(), [](int x) {return x > 50; });
	auto it7 = search_n(vec.begin(), vec.end(), 2,2);

	//搜素某种模式
	vector<int>subvec = { 1,2,2 };
	auto it8 = search(vec.begin(), vec.end(), subvec.begin(), subvec.end());
	auto it9=find_first_of(vec.begin(), vec.end(), subvec.begin(), subvec.end());
	auto it10 = adjacent_find(vec.begin(),vec.end());//寻找两个相同的元素
	auto it11 = adjacent_find(vec.begin(), vec.end(), [](int x, int y) {return x == 2 * y; });
	//比较
	vector<int>vec2 = {1,2,3,4,5,6,7,8,9};
	if ( equal(vec.begin(),vec.end(),vec2.begin()))
	{
		cout << "" << endl;
	}
	//逐个比较元素是否<
	lexicographical_compare(vec.begin(),vec.end(),vec2.begin(),vec2.end());

	//
	is_sorted(vec.begin(),vec.end());
	auto it13 = is_sorted_until(vec.begin(),vec.end());//找到第一个不排序的元素
	is_heap(vec.begin(),vec.end());//判断是否为堆
	is_heap_until(vec.begin(),vec.end());

	//
	all_of(vec.begin(), vec.end(), [](int x) {return x > 80; });
	any_of(vec.begin(), vec.end(), [](int x) {return x < 80; });
	none_of(vec.begin(), vec.end(), [](int x) {return x < 80; });
	system("pause");
	return 0;

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xieshangxin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值