首先得找到list2插入list1的前一个节点和 后一个节点,然后把list2给插入进去。
struct ListNode* mergeInBetween(struct ListNode* list1, int a, int b, struct ListNode* list2){
struct ListNode* curA = list1;
for(int i=0;i<a-1;i++)
{
curA = curA->next;
}
struct ListNode* curB = curA;
for(int i =0;i<b-a+2 ; i++) //这里的b-a+2是(b+1 - (a - 1)) = b-a+2
{
curB = curB->next;
}
curA->next = list2;
while(list2->next != NULL)
{
list2 = list2->next;
}
list2->next = curB;
return list1;
}