Inspiration
What it does
How we built it
Challenges we ran into
Accomplishments that we're proud of
What we learned
What's next for Merge Two Sorted Lists
class LinkedList
{
//Function to merge two sorted linked list.
Node sortedMerge(Node head1, Node head2) {
// This is a "method-only" submission.
// You only need to complete this method
if(head1==null)
return head2;
if(head2==null)
return head1;
if(head1.data>head2.data){
Node temp=head1;
head1=head2;
head2=temp;
}
Node res=head1;
while(head1!=null && head2!=null){
Node temp=null;
while(head1!=null && head1.data<=head2.data){
temp=head1;
head1=head1.next;
}
temp.next=head2;
Node tmp=head1;
head1=head2;
head2=tmp;
}
return res;
} }
Log in or sign up for Devpost to join the conversation.