You are viewing a single comment's thread. Return to all comments →
static SinglyLinkedListNode mergeLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { SinglyLinkedListNode l = null; SinglyLinkedListNode n1 = head1; SinglyLinkedListNode n2 = head2; if(n1==null & n2==null) return null; if(n1==null) return n2; if(n2==null) return n1; if(n1.data<=n2.data){ l = n1; l.next = mergeLists(n1.next,n2); }else{ l = n2; l.next = mergeLists(n1,n2.next); } return l; }
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 →