You are viewing a single comment's thread. Return to all comments →
here is simple code in java...
static SinglyLinkedListNode mergeLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { if(head1==null){return head2;} if(head2==null){return head1;} SinglyLinkedListNode head3 = null; if(head1.data<head2.data){ head3 = head1; head1=head1.next; }else{ head3 = head2; head2 = head2.next; } SinglyLinkedListNode temp = head3; while(head1!=null&&head2!=null){ if(head1.data<head2.data){ temp.next = head1; head1 = head1.next; }else{ temp.next = head2; head2 = head2.next; } temp = temp.next; } if(head1==null){ temp.next = head2; }else{ temp.next = head1; } return head3; }
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 →
here is simple code in java...