Created
July 26, 2015 05:19
-
-
Save krysseltillada/33b6667d985ab0eaf203 to your computer and use it in GitHub Desktop.
exercise 9.31 (b)
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 <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