You are viewing a single comment's thread. Return to all comments →
Node mergeLists(Node headA, Node headB) { Node head= new Node(); Node headTemp= head; while(headA !=null || headB !=null) { if(headA.data<=headB.data && headA !=null && headB !=null) { head.next=headA; headA=headA.next; } else if(headA.data>=headB.data &&headA !=null && headB !=null){ head.next=headB; headB=headB.next; } else if(headA ==null){ head.next=headB; headB=headB.next; } else if(headB ==null){ head.next=headA; headA=headA.next; } head=head.next; } return headTemp.next; }
Seems like cookies are disabled on this browser, please enable them to open this website
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →