How to find the first pair of repeated elements in a list with C++

1 Answer

0 votes
#include <iostream>
#include <list>
#include <algorithm> 
 
int main ()
{
    std::list<int> l = { 3, 2, 1, 5, 5, 7, 1, 5, 9, 9, 9 };
     
    std::list<int>::iterator it;
 
    it = std::adjacent_find(l.begin(), l.end());
 
    if (it != l.end())
        std::cout << "The first pair of repeated elements start with: " << *it << '\n';
 
 
    return 0;
}
    

    
/*
run:
    
The first pair of repeated elements start with: 5
    
*/

 



answered Apr 15, 2020 by avibootz
...