diff options
author | Oskar <[email protected]> | 2024-11-01 10:44:53 +0100 |
---|---|---|
committer | Oskar <[email protected]> | 2024-11-01 10:44:53 +0100 |
commit | 77b344e13eae4b4439f96a8d062151da03bf8263 (patch) | |
tree | c7ed835678354e1877383884f7c061b5930b7328 /9p34.cpp | |
parent | ce6f87441ab2343f7730139f20d25b41e9dd6080 (diff) |
been a while, took a break i guess
Diffstat (limited to '9p34.cpp')
-rw-r--r-- | 9p34.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1,12 +1,26 @@ #include <iostream> +#include <vector> /* * - * Description + * 9.34 * * */ int main () { + + // Prediction: The program will get stuck on the first odd value and keep inserting it indefinitely + std::vector<int> vi = {1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; + auto iter = vi.begin(); + while (iter != vi.end()) { + if (*iter % 2) { // when it's odd + iter = vi.insert(iter, *iter); // insert copy of *iter before iter, return iterator to inserted value + std::cout << "inserted value: " << *iter << "\n"; + } + + ++iter; // go one step forwards + } + return 0; } |