fork(3) download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <list>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. list<int> data{1, 2, 2, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 6};
  11.  
  12. for (auto i = data.begin(); i != data.end();)
  13. {
  14. auto n = std::next(i);
  15.  
  16. if (n == data.end())
  17. break;
  18.  
  19. if (*i == *n)
  20. {
  21. i = data.erase(i);
  22. i = data.erase(i);
  23. }
  24. else
  25. i++;
  26. }
  27.  
  28. for (auto x : data)
  29. cout << x << " ";
  30.  
  31. cout << endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6