Created
November 18, 2018 08:01
Star
You must be signed in to star a gist
This file contains 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