How to find the start index of a sequence of N elements with the same value in deque using C++

1 Answer

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

using std::cout;
using std::endl;
using std::deque;

int main()
{
	deque<int> dq = { 1, 3, 2, 1, 4, 4, 4, 6, 4, 4 };
	deque<int>::iterator pos;

	pos = search_n(dq.begin(), dq.end(), 3, 4);

	if (pos != dq.end())
		cout << "start in index: " << distance(dq.begin(), pos) << endl;
	else
		cout << "not found" << endl;

	return 0;
}

/*
run:

start in index: 4

*/

 



answered Feb 21, 2018 by avibootz

Related questions

1 answer 298 views
1 answer 164 views
1 answer 197 views
1 answer 186 views
1 answer 171 views
2 answers 232 views
...