Created
July 26, 2015 05:17
-
-
Save krysseltillada/472e988e7bf84179ad9f to your computer and use it in GitHub Desktop.
exercise 9.31 (a)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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