Skip to content

Instantly share code, notes, and snippets.

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