Created
November 1, 2016 05:08
-
-
Save YaoC/919685686e428e1cb429dc1b1a462f9d 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 <iostream> | |
using namespace std; | |
struct ListNode{ | |
char info; | |
ListNode* next; | |
ListNode(char newinfo, ListNode* newNext) { | |
info = newinfo; | |
next = newNext; | |
} | |
}; | |
static ListNode* stringToList(const char* s) { | |
if (*s == '\0') | |
return nullptr; | |
return new ListNode(*s, stringToList(s + 1)); | |
} | |
int main() { | |
char* s = "asdfghj"; | |
ListNode* head = stringToList(s); | |
ListNode* p = head; | |
while (p->next) { | |
cout << p->info; | |
p = p->next; | |
} | |
cout << p->info << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment