head2->next =curr;///2 这一步和上一步就是头插法了 curr= prev->next;///curr指针后移一个位置 }returndummy.next; } 头插法建立链表 ListNode *head = nullptr; ListNode dummy(-1); dummy.next = head; vector<int> nums = {1,2,3,4}; for(int i = 0;i<nums.size();i++){ ListN...
next(NULL) {} //初始化当前结点值为x,指针为空 };如何向ListNode中插入新的结点:从键盘输入Lis...
* left = fakehead; ListNode* right = fakehead ->next; while(right) { if(left ->val == right ->val) { left ->next = right ->next; right = right ->next; if(right == nullptr) break; } else { left = left ->next; right = right ->next; } } return fakehead ->next; }...