Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created July 26, 2015 05:19
Show Gist options
  • Save krysseltillada/33b6667d985ab0eaf203 to your computer and use it in GitHub Desktop.
Save krysseltillada/33b6667d985ab0eaf203 to your computer and use it in GitHub Desktop.
exercise 9.31 (b)
#include <iostream>
#include <list>
int main ()
{
std::list <int> v1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
auto curr = v1.begin();
while (curr != v1.end()) {
if (*curr % 2) {
curr = v1.insert (curr, *curr);
++curr;
++curr;
} else {
curr = v1.erase (curr);
}
}
for (auto it = v1.begin(); it != v1.end(); ++it)
std::cout << *it << " ";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment