Skip to content

Instantly share code, notes, and snippets.

@YaoC
Created November 1, 2016 05:08
Show Gist options
  • Save YaoC/919685686e428e1cb429dc1b1a462f9d to your computer and use it in GitHub Desktop.
Save YaoC/919685686e428e1cb429dc1b1a462f9d to your computer and use it in GitHub Desktop.
#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