New ListNode ( -1= dummy3; while (head2!=null&&head1!=null) { Pre.next=head1; = Head1.next; Head1.next=head2; = Head2.next; Head2.next=null; Pre=head2; Head1=head1next; Head2=head2next;}
The code above is the correct notation.
1ListNode dummy3 =NewListNode (-1);2ListNode pre =Dummy3;3 while(head2!=NULL&&head1!=NULL){4pre.next=Head1;5Pre.next.next =head2;6 //ListNode head1next = head1.next;7 //head1.next=head2;8 //ListNode head2next = head2.next;9 //Head2.next=null;TenPre=head2; Onehead1=Head.next; AHead2=Head.next; -}
The above code was wrong, and after the execution of the 5th line of code, the Head1 's next pointer was actually lost, because the 5th line of code was actually head1 the next pointer was redefined, pointing to head2, but before changing the pointer, Its original next pointer has not been modified, and the next pointer will be the new head1.
Beware of it!
[Bug] Two linked list, staggered to another linked list