How to find element in deque using search criterion in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>
#include <deque>

int main()
{
	std::deque<int> dq = { 3, 1, 21, 12, 13, 6, 8, 7 };

	int x = 4;
	int y = 13;
	auto pos = find_if(dq.cbegin(), dq.cend(), [=](int i) { return i > x && i < y;});

	std::cout << "The first element that >4 and <13 is: " << *pos << std::endl;

	return 0;
}

/*
run:

The first element that >4 and <13 is: 12

*/

 



answered Jan 1, 2018 by avibootz

Related questions

1 answer 205 views
1 answer 269 views
1 answer 168 views
1 answer 280 views
1 answer 172 views
...