MCPcopy Create free account
hub / github.com/EricPengShuai/Interview / stringToListNode

Function stringToListNode

memo/listnode.cpp:77–91  ·  view source on GitHub ↗

注意构造链表的方式

Source from the content-addressed store, hash-verified

75
76// 注意构造链表的方式
77ListNode* stringToListNode(string input) {
78 // Generate list from the input
79 vector<int> list = stringToIntegerVector(input);
80
81 // Now convert that list into linked list
82 ListNode* dummyRoot = new ListNode(0);
83 ListNode* ptr = dummyRoot;
84 for(int item : list) {
85 ptr->next = new ListNode(item);
86 ptr = ptr->next;
87 }
88 ptr = dummyRoot->next;
89 delete dummyRoot;
90 return ptr;
91}
92
93
94// 链表转字符串

Callers 1

mainFunction · 0.85

Calls 1

stringToIntegerVectorFunction · 0.85

Tested by

no test coverage detected