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