Created
November 18, 2018 08:01
-
-
Save ridiculousfish/c9c2a0509ec8de488d0aba7c30cff056 to your computer and use it in GitHub Desktop.
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 <memory> | |
| #include <string> | |
| struct CharList { | |
| char c; | |
| std::unique_ptr<CharList> next; | |
| explicit CharList(char c) : c(c) {} | |
| }; | |
| CharList make_list(const std::string &s) { | |
| CharList res{'a'}; | |
| auto *tail = &res.next; | |
| for (char c : s) { | |
| *tail = std::make_unique<CharList>(c); | |
| tail = &(*tail)->next; | |
| } | |
| return res; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment