struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
int main() {
ListNode *pHead = new ListNode(NULL);
ListNode *pPre = pHead, *pNode = NULL;
vector<int> vec = { 1,2,3,3,4,4,5 };
for (int i = 0; i < vec.size(); i++) {
pNode = new ListNode(vec[i]);
pPre->next = pNode;
pPre = pPre->next; pNode = pNode->next;
}
return 0;
}
用数组创建链表模板
最新推荐文章于 2023-03-18 17:30:09 发布