用数组创建链表模板

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;
}

版权声明:本文为weixin_43313092原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。