Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@


// Complete the mergeLists function below.

/*
* For your reference:
*
* SinglyLinkedListNode {
* int data;
* SinglyLinkedListNode* next;
* };
*
*/
SinglyLinkedListNode* mergeLists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) {
SinglyLinkedListNode* temp;

if(head1==NULL&&head2==NULL){
return NULL;

}

if(head1==NULL) return head2;
if(head2==NULL) return head1;

if(head1->data<head2->data){
head1->next=mergeLists(head1->next,head2);
return head1;
}

else{
head2->next=mergeLists(head2->next,head1);
return head2;
}

}