[Solved]List inserting
I have a list of n integers. I'm trying to add after each even number it's double. Below is my try: #include <iostream> #include <list> using namespace std; int main() { int n, x, aux; cin >> n; list<int> l; for(int i = 0; i < n; i++){ cin >> x; l.push_back(x); } list<int>::iterator it; it = l.begin(); for( ; it != l.end(); ++it){ aux = *it; if( aux % 2 == 0){ ++it; l.insert(it, aux * 2); } continue; } list<int>::iterator j; for(j = l.begin(); j != l.end(); ++j) cout << *j << " "; return 0; } It works, but the doubles are added twice. I've tried to increase the iterator and the continue keyword but I've got the same results. How can I fix this?