diff options
author | Oskar <[email protected]> | 2024-10-15 17:05:33 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-10-15 17:05:33 +0200 |
commit | 7db4642f463244fdbacd2b20f261398c9de38fd9 (patch) | |
tree | a6f79131c824e489518749b17b7f4e452046e36b /9p28.cpp | |
parent | 428d857359b5d8b639ca41b03ca8fc8b3d143a50 (diff) |
more
Diffstat (limited to '9p28.cpp')
-rw-r--r-- | 9p28.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/9p28.cpp b/9p28.cpp new file mode 100644 index 0000000..3098381 --- /dev/null +++ b/9p28.cpp @@ -0,0 +1,53 @@ +#include <iostream> +#include <forward_list> + +/* + * + * 9.28 + * + * + */ + +std::forward_list<std::string> &ch9e28(std::forward_list<std::string> &fl, std::string findme, std::string s) { + + bool success = false; + auto beg = fl.begin(); + auto end = fl.cend(); + while(beg != end) { + if(*beg == findme) { + beg = fl.insert_after(beg, s); + success = true; + break; + } else { + ++beg; + } + } + + if(success == false) { + auto sbeg = fl.begin(); + auto sbbeg = fl.before_begin(); + for(; sbeg != end ; ++sbeg, ++sbbeg) { + + } + + fl.insert_after(sbbeg, s); + + } + + return fl; +} + +int main () { + + /* + My solution felt a bit hacky but it works, whatever. + */ + std::forward_list<std::string> flm = {"HELLO", "AA", "YO", "HELL"}; + std::string s = "HELLOafter"; + ch9e28(flm, "HELLO", s); + for(auto &a : flm) { + std::cout << a << std::endl; + } + + return 0; +} |